Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:ContentProvider出现数据库问题-java.lang.IllegalStateException_Android_Sqlite_Android Contentprovider - Fatal编程技术网

Android:ContentProvider出现数据库问题-java.lang.IllegalStateException

Android:ContentProvider出现数据库问题-java.lang.IllegalStateException,android,sqlite,android-contentprovider,Android,Sqlite,Android Contentprovider,在我的例子中,我将ContentProvider与CursorAdapter一起使用,内容提供程序具有查询和插入的方法。如果bulkInsert在查询方法之前运行,则会出现异常: java.lang.IllegalStateException: database /data/data/com.example/databases/testdb (conn#0) already closed 我认为这是因为在bulkInsert方法中: public int bulkInsert(Uri ur

在我的例子中,我将ContentProvider与CursorAdapter一起使用,内容提供程序具有查询和插入的方法。如果bulkInsert在查询方法之前运行,则会出现异常:

java.lang.IllegalStateException: database /data/data/com.example/databases/testdb (conn#0) already closed  
我认为这是因为在bulkInsert方法中:

public int bulkInsert(Uri uri, ContentValues[] insertValuesArray) {
    switch (sUriMatcher.match(uri)) {
        case ROUTE_ENTRIES:
            SQLiteDatabase localSQLiteDatabase = mDatabaseHelper.getWritableDatabase();

            localSQLiteDatabase.beginTransaction();
            localSQLiteDatabase.setTransactionSuccessful();

            // do the work

            // Ends the transaction and closes the current db instances
            localSQLiteDatabase.endTransaction();
            localSQLiteDatabase.close();
    }
}
如您所见,localSQLiteDatabase.close()是在bulkInsert方法中调用的。我这样做是因为我遵循了来自google的threadsample。链接:

有人能建议我是否应该关闭bulkInsert中的数据库吗?如果我不关上,有没有漏水

非常感谢

干杯


Martin

您正在调用
mDatabaseHelper.getReadableDatabase()在查询()中?你好,karakuri,是的。我在查询方法中使用这个