gpt4 book ai didi

java - 如何修复空光标 - android studio

转载 作者:行者123 更新时间:2023-12-01 18:28:38 27 4
gpt4 key购买 nike

我真的很感激一些帮助!我正在做一个项目,但我被困在这部分了!

登录猫:

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)

代码:

 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) }

最佳答案

您有光标对象,但您没有像对 arrayListNote 和上下文那样初始化该对象,因此您有空对象引用。

关于java - 如何修复空光标 - android studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60196022/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com