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

标签 java sqlite android-studio android-layout

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

登录猫:

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/

相关文章:

java - 关闭 ProgressDialog 时出错 - E/ViewRootImpl : sendUserActionEvent() mView == null

java - SonarQube 吹毛求疵? - "Right curly brace and next "else"、 "catch"和 "finally"关键字应位于同一行"

java - 编写一个与 Iphone、Ipod 或 Ipad 交互的 Java 程序以同步文件(音乐、书籍、照片)?与 Itunes 的方式大致相同

python - 为什么我的 sqlite3 外键不起作用?

javascript - 如何从 .ejs 获取值到 javascript 文件

android - 不支持的方法 : AndroidArtifact. getBuildConfigFields()

Android Studio 将语法标记为错误,但 gradle 编译

java - java中使用bufferedstream复制时的数据大小差异

java - java.lang.System.arraycopy(Native Method) 线程 "main"java.lang.ArrayIndexOutOfBoundsException 中的异常

sqlite - Entity Framework 7 - Code First - SQLite - 在运行时使用 Apply Migrations 管理 DB