Android:ContentProvider出现数据库问题-java.lang.IllegalStateException
在我的例子中,我将ContentProvider与CursorAdapter一起使用,内容提供程序具有查询和插入的方法。如果bulkInsert在查询方法之前运行,则会出现异常: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
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,是的。我在查询方法中使用这个