0

I would really appreciate some help! I am working on a project and I am stuck at this part!

Log cat:

java.lang.NullPointerException: Attempt to invoke interface method 'int android.database.Cursor.getColumnIndex(java.lang.String)' on a null object reference
at com.example.workhours.NotesCustomAdapter.onBindViewHolder(NotesCustomAdapter.java:38)
at com.example.workhours.NotesCustomAdapter.onBindViewHolder(NotesCustomAdapter.java:16)

code:

 16)  public class NotesCustomAdapter extends RecyclerView.Adapter<NotesCustomAdapter.ViewHolder>{
 17)      private ArrayList<newNote> arrayListNote;
 18)      private Context context;
 19)      Cursor cursor;

 20)   public NotesCustomAdapter(ArrayList<newNote> arrayListNote, Context context) {
 21)        this.arrayListNote = arrayListNote;
 22)        this.context = context;
 23)    }

 35)    @Override
 36)    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
 37)        holder.notePadTextView.setText(arrayListNote.get(position).getNote());
 38)        long id = cursor.getLong(cursor.getColumnIndex(DataBaseHelper.COL_0));
 39)        holder.itemView.setTag(id);
 40)    }
Dark Shadow
  • 23
  • 1
  • 6

1 Answers1

0

You have cursor object but you did not initialize this object as you did for arrayListNote and context so you have null object reference.

emredmrcn
  • 144
  • 1
  • 5
  • Thank you for that! But how do I initialize the cursor? – Dark Shadow Feb 14 '20 at 02:39
  • [First link](https://stackoverflow.com/questions/37050574/android-cursor-initialization) , [Second link](https://stackoverflow.com/questions/20240249/make-sure-the-cursor-is-initialized-correctly-before-accessing-data-from-it) You can check these links. – emredmrcn Feb 14 '20 at 15:54
  • Sorry, I really do not know how to implement that into my own code – Dark Shadow Feb 15 '20 at 12:57