Cannot resolve method

Asked

Viewed 356 times

0

I’m making an application for Android in which there is a Fragment to add a task (with title and description), and a Fragment that lists all the tasks stored in a Singleton.

In Tasks Fragment when listing Title and Job Description android studio seems to be unable to find the method getTitulo() and getDescricao() in Tasks.java, both methods have the error:

Cannot resolve method.

Java tasks.:

package com.example.desen.gestoradetarefas;

public class Tarefas {
    private String titulo;
    private String descricao;

    public String getTitulo() {
        return titulo;
    }

    public void setTitulo(String titulo) {
        this.titulo = titulo;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }
}

Tarefasfragment.java:

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class TarefasFragment extends Fragment {


    public TarefasFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_tarefas, container, false);

        container = (ViewGroup) v.findViewById(R.id.container);


        List<Tarefas> tar = TarefaSingleton.getInstance().getTarefas();


        if (tar != null) {
            CardView cardView = (CardView) LayoutInflater.from(getActivity())
                    .inflate(R.layout.card, container, false);
            cardView.findViewById(R.id.titulo);
            TextView titulo = (TextView) cardView.findViewById(R.id.titulo);
            TextView mensagem = (TextView) cardView.findViewById(R.id.mensagem);

            for(int i = 0; i < tar.size(); i++){
                titulo.setText(tar.getTitulo());
                mensagem.setText(tar.getDescricao());
                container.addView(cardView);
            }
        }
       return v;
    }
}

Tasksingleton.java:

package com.example.desen.gestoradetarefas;

import java.util.ArrayList;
import java.util.List;

public class TarefaSingleton {

    private static final TarefaSingleton
            INSTANCE = new TarefaSingleton();

    private List<Tarefas> tarefas = new ArrayList<>();

    private TarefaSingleton() {

    }

    public static TarefaSingleton getInstance() {
        return INSTANCE;
    }

    public List<Tarefas> getTarefas() {
        return tarefas;
    }

    public void setTarefas(List<Tarefas> tarefas) {
        this.tarefas = tarefas;
    }
}

1 answer

1

Are you calling the getDescricao and getTarefa of List and not your task object. Try it this way:

            for(Tarefa tarefa: tar) {
                titulo.setText(tarefa.getTitulo());
                mensagem.setText(tarefa.getDescricao());
                container.addView(cardView);
            }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.