-2

I'm Building a todo app, I declared methods in separate java file and when I wanna access them in another java file they are saying 'can't resolve the method'

You can see the whole project at https://github.com/RamcharanS/MyTODO_Be_Productive

Please Help me with this and if possible please check and give a small review on my code

Java file of Methods

package com.example.mytodo;

public class my_todo {
    String titledoes;
    String datedoes;
    String descdoes;
    String keydoes;

    public my_todo() {
    }

    public my_todo(String titledoes, String datedoes, String descdoes, String keydoes) {
        this.titledoes = titledoes;
        this.datedoes = datedoes;
        this.descdoes = descdoes;
        this.keydoes = keydoes;
    }



    public String getKeydoes() {
        return keydoes;
    }

    public void setKeydoes(String keydoes) {
        this.keydoes = keydoes;
    }

    public String getTitledoes() {
        return titledoes;
    }

    public void setTitledoes(String titledoes) {
        this.titledoes = titledoes;
    }

    public String getDatedoes() {
        return datedoes;
    }

    public void setDatedoes(String datedoes) {
        this.datedoes = datedoes;
    }

    public String getDescdoes() {
        return descdoes;
    }

    public void setDescdoes(String descdoes) {
        this.descdoes = descdoes;
    }
}

This is the Java file Giving me Error Method : getTitledoes() getDescdoes() getDatedoes()

package com.example.mytodo;


import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.mytodo.R;

import org.w3c.dom.Text;

import java.util.ArrayList;

public class DoesAdapter extends RecyclerView.Adapter<DoesAdapter.MyViewHolder>{

    Context context;
    ArrayList myDoes;

    public DoesAdapter(Context c, ArrayList p) {
        context = c;
        myDoes = p;
    }

    @NonNull
    @Override
    public  MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i){
    return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.new_todo, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i){
        MyViewHolder.titledoes.setText(myDoes.get(i).getTitledoes());
        MyViewHolder.descdoes.setText(myDoes.get(i).getDescdoes());
        MyViewHolder.datedoes.setText(myDoes.get(i).getDatedoes());
    }



    @Override
    public int getItemCount(){
        return myDoes.size();
    }
    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView titledoes, descdoes, datedoes;

        public MyViewHolder(@NonNull View itemView){
            super(itemView);
            titledoes = (TextView) itemView.findViewById(R.id.titledoes);
            descdoes = (TextView) itemView.findViewById(R.id.descdoes);
            datedoes = (TextView) itemView.findViewById(R.id.datedoes);
        }
    }

}

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Aiero
  • 3
  • 3

3 Answers3

1

Create your list like this

// modify your adapter class like this
  Context context;
 ArrayList<my_todo> myDoes;

public DoesAdapter(Context c, ArrayList<my_todo> p) {
    context = c;
    myDoes = p;
}


// create list in your activity
 ArrayList<my_todo> list=new ArrayList<>();
 list.add(new my_todo("title","date","desc","key"));

 // pass list  to adapter class
 new DoesAdapter(this,list);
Dharmender Manral
  • 1,504
  • 1
  • 6
  • 7
0

Try declare your ArrayList myDoes as ArrayList<my_todo> myDoes and in your Adapter constructor parameter too. Only ArrayList you have an ArrayList of Object type.

Marcos Boaventura
  • 4,641
  • 1
  • 20
  • 27
0

Cause for your problem is that you are using ArrayList without specifying generic type, this means that when you get element from list it will be Object and not my_todo, you can simply fix this problem by adding generic type which you want list to be:

change ArrayList myDoes; to List<my_todo> myDoes;

and constructor parameter to List<my_todo> p.

Note that I have used List instead of ArrayList, because it is more abstract type, its best practice to always use most abstract type that is possible in given situation.

UPDATE:

I would gladly explain you how generics work but that would result in quite long answer, seeing that you are beginner I would suggest to find some Java book or online course, most of those cover generics, how they work and how to use them, also you can read this tutorial from Oracle itself

FilipRistic
  • 2,661
  • 4
  • 22
  • 31
  • Thanks a lot, it worked but I didn't understand my error properly please help me to understand it – Aiero May 31 '19 at 18:51