Android:IllegalStateException:尝试重新打开已关闭的对象:SQLiteDatabase

时间:2015-10-20 07:06:49

标签: android

我在整个活动中遇到同样的错误,我的游标代码为IllegalStateException:尝试重新打开已经关闭的对象:SQLiteDatabase。这是我的代码。我不明白代码出错了。谢谢先生。

Cursor cursor = db.rawQuery("select * from ActivityObjectList where activityId " + "= ? ", new String[]{strListItem_ActivityId});
                imageArray.clear();
                if (cursor.moveToFirst()) {
                    do {
                        String imagePath = cursor.getString(cursor.getColumnIndex("imageaudioPath"));
                        imageArray.add(imagePath);
                    }
                    while (cursor.moveToNext());
                }
                cursor.close();
                db.close();

这是onCreate()方法中的代码。

dbhelper = new MyDbHelper(this);
            dbhelper.onOpen(db);
            db = dbhelper.getWritableDatabase();

这是我的日志cat错误

 java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/com.example.tazeen.classnkk/databases/ClassNKK
            at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
            at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1312)
            at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)
            at com.example.tazeen.classnkk.AllPosts_Page$MyListAdapter.getView(AllPosts_Page.java:1245)
            at android.widget.AbsListView.obtainView(AbsListView.java:2346)
            at android.widget.ListView.makeAndAddView(ListView.java:1864)
            at android.widget.ListView.fillDown(ListView.java:698)
            at android.widget.ListView.fillFromTop(ListView.java:759)
            at android.widget.ListView.layoutChildren(ListView.java:1673)
            at android.widget.AbsListView.onLayout(AbsListView.java:2150)
            at android.view.View.layout(View.java:15595)
            at android.view.ViewGroup.layout(ViewGroup.java:4966)
            at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:562)

0 个答案:

没有答案