只要应用程序到达执行 cursor.getString() 的行,它就会崩溃。我已经尝试了 cursor.getString() 和 cursor.getString(cursor.getColumnIndex(" ")) 但它仍然崩溃它执行的方法:public void populateView(){ Cursor data = myDb.getData(); data.moveToFirst(); String title = data.getString(data.getColumnIndex(1)); newsList.add(new NewsItem(R.drawable.ic_home_black_24dp, title, "Description")); mAdapter = new NewsItemAdapter(newsList); mRecyclerView.setAdapter(mAdapter);}DatabaseHelper类中的方法:public Cursor getData(){ SQLiteDatabase db = this.getReadableDatabase(); String query = "SELECT * FROM " + TABLE_NAME_REPORT; Cursor data = db.rawQuery(query, null); data.close(); db.close(); return data;}PS NewsItem 类接受这些参数:public NewsItem(int imageResource, String title, String desc){ mImageResource = imageResource; mTitle = title; mDescription = desc;}Process: com.example.reportingapplication, PID: 32448java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteQuery: SELECT * FROM report_data at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55) at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:58) at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:151) at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:139) at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:220) at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:265) at com.example.reportingapplication.Fragments.HomeFragment.populateView(HomeFragment.java:104) at com.example.reportingapplication.Fragments.HomeFragment$1.onClick(HomeFragment.java:58)
添加回答
举报
0/150
提交
取消