这段代码:
public void foo() {
new Thread() {
@Override
public void run() {
ShaufelDatabaseHelper dbHelper = ShaufelDatabaseHelper.getInstance(parentActivity);
sqliteDatabase connection = null;
Cursor queryData = null;
final String[] values = new String[8];
try{
connection = dbHelper.getReadableDatabase();
queryData = connection.rawQuery( // line 132
"SELECT name,firstname,section,row,gravenr,type,workorder,comment "+
"FROM orders,graves "+
"WHERE orders.id=? AND graves.id=orders.id",new String[] {orderID});
queryData.moveToFirst(); // line 138
// ...
} catch(Throwable t) {
// ...
}
}.start();
}
给我这些例外:
10-29 15:19:55.103: E/AndroidRuntime(23102): FATAL EXCEPTION: Thread-1387
10-29 15:19:55.103: E/AndroidRuntime(23102): java.lang.IllegalMonitorStateException
10-29 15:19:55.103: E/AndroidRuntime(23102): at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:126)
10-29 15:19:55.103: E/AndroidRuntime(23102): at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1239)
10-29 15:19:55.103: E/AndroidRuntime(23102): at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:431)
10-29 15:19:55.103: E/AndroidRuntime(23102): at android.database.sqlite.sqliteDatabase.unlock(sqliteDatabase.java:487)
10-29 15:19:55.103: E/AndroidRuntime(23102): at android.database.sqlite.sqliteDirectCursorDriver.query(sqliteDirectCursorDriver.java:62)
10-29 15:19:55.103: E/AndroidRuntime(23102): at android.database.sqlite.sqliteDatabase.rawQueryWithFactory(sqliteDatabase.java:1564)
10-29 15:19:55.103: E/AndroidRuntime(23102): at android.database.sqlite.sqliteDatabase.rawQuery(sqliteDatabase.java:1538)
10-29 15:19:55.103: E/AndroidRuntime(23102): at de.l_one.app.shaufel.OrderDetailView$3.run(OrderDetailView.java:132)
10-29 15:21:07.953: E/sqliteQuery(23133): exception: library routine called out of sequence; query: SELECT name,comment FROM orders,graves WHERE orders.id=? AND graves.id=orders.id
10-29 15:21:07.953: E/sql order detail(23133): android.database.sqlite.sqliteMisuseException: library routine called out of sequence
10-29 15:21:07.953: E/sql order detail(23133): android.database.sqlite.sqliteMisuseException: library routine called out of sequence
10-29 15:21:07.953: E/sql order detail(23133): at android.database.sqlite.sqliteQuery.nativeFillWindow(Native Method)
10-29 15:21:07.953: E/sql order detail(23133): at android.database.sqlite.sqliteQuery.fillWindow(sqliteQuery.java:86)
10-29 15:21:07.953: E/sql order detail(23133): at android.database.sqlite.sqliteCursor.fillWindow(sqliteCursor.java:164)
10-29 15:21:07.953: E/sql order detail(23133): at android.database.sqlite.sqliteCursor.getCount(sqliteCursor.java:156)
10-29 15:21:07.953: E/sql order detail(23133): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:161)
10-29 15:21:07.953: E/sql order detail(23133): at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:201)
10-29 15:21:07.953: E/sql order detail(23133): at de.l_one.app.shaufel.OrderDetailView$3.run(OrderDetailView.java:138)
10-29 15:22:52.983: E/AndroidRuntime(23133): FATAL EXCEPTION: Thread-1411
10-29 15:22:52.983: E/AndroidRuntime(23133): java.lang.IllegalStateException: database /data/data/de.l_one.app.shaufel/databases/poidatabase (conn# 0) already closed
10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteDatabase.verifyDbIsOpen(sqliteDatabase.java:2082)
10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteCompiledsql.(sqliteCompiledsql.java:58)
10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteProgram.compilesql(sqliteProgram.java:143)
10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteProgram.compileAndbindAllArgs(sqliteProgram.java:361)
10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteProgram.(sqliteProgram.java:127)
10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteProgram.(sqliteProgram.java:94)
10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteQuery.(sqliteQuery.java:53)
10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteDirectCursorDriver.query(sqliteDirectCursorDriver.java:47)
10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteDatabase.rawQueryWithFactory(sqliteDatabase.java:1564)
10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteDatabase.rawQuery(sqliteDatabase.java:1538)
10-29 15:22:52.983: E/AndroidRuntime(23133): at de.l_one.app.shaufel.OrderDetailView$3.run(OrderDetailView.java:132)
这些不会在一次运行中抛出,而是(似乎是)随机抛出.抛出Exception时没有模式,有时根本不会抛出Exception.
我在我的应用程序中使用相同的方法,它没有任何问题.我没有最小的线索来自IllegalStateException,因为数据库没有关闭,至少不是我. (根据SO的一些答案,这是正常的,在某些情况下甚至比手动关闭你的dbs更好).
代码注释:
ShaufelDatabaseHelper是一个扩展sqliteOpenHelper的Singleton.它用于一般工作的不同活动,这似乎是唯一的例外.
我刚刚在第二台设备上测试过,没有抛出任何异常,一切正常.
抛出Exceptions的设备是运行android 4.0.3的lenovo thinkpad.
没有Exceptions运行的是运行Android 2.3.4的HTC Sensation Z710e.
有谁知道这会导致什么?
E:我不知道它是否有帮助但是在sqliteMisuseException之前记录了这个:
10-29 16:07:46.530: I/sqliteDatabaseCpp(23728): sqlite returned: error code = 21,msg = API called with NULL prepared statement,db=/data/data/de.l_one.app.shaufel/databases/poidatabase
10-29 16:07:46.530: I/sqliteDatabaseCpp(23728): sqlite returned: error code = 21,msg = misuse at line 58929 of [8609a15dfa],msg = API call with invalid database connection pointer,msg = misuse at line 106340 of [8609a15dfa],msg = misuse at line 106271 of [8609a15dfa],db=/data/data/de.l_one.app.shaufel/databases/poidatabase
这段代码: public void foo() { new Thread() { @Override public void run() { ShaufelDatabaseHelper dbHelper = ShaufelDatabaseHelper.getInstance(parentActivity); sqliteDatabase connection = null; Cursor queryData = null; final String[] values = new String[8]; try{ connection = dbHelper.getReadableDatabase(); queryData = connection.rawQuery( // line 132 "SELECT name,firstname,section,row,gravenr,type,workorder,comment "+ "FROM orders,graves "+ "WHERE orders.id=? AND graves.id=orders.id",new String[] {orderID}); queryData.moveToFirst(); // line 138 // ... } catch(Throwable t) { // ... } }.start(); } 给我这些例外: 10-29 15:19:55.103: E/AndroidRuntime(23102): FATAL EXCEPTION: Thread-1387 10-29 15:19:55.103: E/AndroidRuntime(23102): java.lang.IllegalMonitorStateException 10-29 15:19:55.103: E/AndroidRuntime(23102): at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:126) 10-29 15:19:55.103: E/AndroidRuntime(23102): at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1239) 10-29 15:19:55.103: E/AndroidRuntime(23102): at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:431) 10-29 15:19:55.103: E/AndroidRuntime(23102): at android.database.sqlite.sqliteDatabase.unlock(sqliteDatabase.java:487) 10-29 15:19:55.103: E/AndroidRuntime(23102): at android.database.sqlite.sqliteDirectCursorDriver.query(sqliteDirectCursorDriver.java:62) 10-29 15:19:55.103: E/AndroidRuntime(23102): at android.database.sqlite.sqliteDatabase.rawQueryWithFactory(sqliteDatabase.java:1564) 10-29 15:19:55.103: E/AndroidRuntime(23102): at android.database.sqlite.sqliteDatabase.rawQuery(sqliteDatabase.java:1538) 10-29 15:19:55.103: E/AndroidRuntime(23102): at de.l_one.app.shaufel.OrderDetailView$3.run(OrderDetailView.java:132) 10-29 15:21:07.953: E/sqliteQuery(23133): exception: library routine called out of sequence; query: SELECT name,comment FROM orders,graves WHERE orders.id=? AND graves.id=orders.id 10-29 15:21:07.953: E/sql order detail(23133): android.database.sqlite.sqliteMisuseException: library routine called out of sequence 10-29 15:21:07.953: E/sql order detail(23133): android.database.sqlite.sqliteMisuseException: library routine called out of sequence 10-29 15:21:07.953: E/sql order detail(23133): at android.database.sqlite.sqliteQuery.nativeFillWindow(Native Method) 10-29 15:21:07.953: E/sql order detail(23133): at android.database.sqlite.sqliteQuery.fillWindow(sqliteQuery.java:86) 10-29 15:21:07.953: E/sql order detail(23133): at android.database.sqlite.sqliteCursor.fillWindow(sqliteCursor.java:164) 10-29 15:21:07.953: E/sql order detail(23133): at android.database.sqlite.sqliteCursor.getCount(sqliteCursor.java:156) 10-29 15:21:07.953: E/sql order detail(23133): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:161) 10-29 15:21:07.953: E/sql order detail(23133): at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:201) 10-29 15:21:07.953: E/sql order detail(23133): at de.l_one.app.shaufel.OrderDetailView$3.run(OrderDetailView.java:138) 10-29 15:22:52.983: E/AndroidRuntime(23133): FATAL EXCEPTION: Thread-1411 10-29 15:22:52.983: E/AndroidRuntime(23133): java.lang.IllegalStateException: database /data/data/de.l_one.app.shaufel/databases/poidatabase (conn# 0) already closed 10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteDatabase.verifyDbIsOpen(sqliteDatabase.java:2082) 10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteCompiledsql.(sqliteCompiledsql.java:58) 10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteProgram.compilesql(sqliteProgram.java:143) 10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteProgram.compileAndbindAllArgs(sqliteProgram.java:361) 10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteProgram.(sqliteProgram.java:127) 10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteProgram.(sqliteProgram.java:94) 10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteQuery.(sqliteQuery.java:53) 10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteDirectCursorDriver.query(sqliteDirectCursorDriver.java:47) 10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteDatabase.rawQueryWithFactory(sqliteDatabase.java:1564) 10-29 15:22:52.983: E/AndroidRuntime(23133): at android.database.sqlite.sqliteDatabase.rawQuery(sqliteDatabase.java:1538) 10-29 15:22:52.983: E/AndroidRuntime(23133): at de.l_one.app.shaufel.OrderDetailView$3.run(OrderDetailView.java:132) 这些不会在一次运行中抛出,而是(似乎是)随机抛出.抛出Exception时没有模式,有时根本不会抛出Exception. 我在我的应用程序中使用相同的方法,它没有任何问题.我没有最小的线索来自IllegalStateException,因为数据库没有关闭,至少不是我. (根据SO的一些答案,这是正常的,在某些情况下甚至比手动关闭你的dbs更好). 代码注释: ShaufelDatabaseHelper是一个扩展sqliteOpenHelper的Singleton.它用于一般工作的不同活动,这似乎是唯一的例外. 我刚刚在第二台设备上测试过,没有抛出任何异常,一切正常. 抛出Exceptions的设备是运行android 4.0.3的lenovo thinkpad. 没有Exceptions运行的是运行Android 2.3.4的HTC Sensation Z710e. 有谁知道这会导致什么? E:我不知道它是否有帮助但是在sqliteMisuseException之前记录了这个: 10-29 16:07:46.530: I/sqliteDatabaseCpp(23728): sqlite returned: error code = 21,msg = API called with NULL prepared statement,db=/data/data/de.l_one.app.shaufel/databases/poidatabase 10-29 16:07:46.530: I/sqliteDatabaseCpp(23728): sqlite returned: error code = 21,msg = misuse at line 58929 of [8609a15dfa],msg = API call with invalid database connection pointer,msg = misuse at line 106340 of [8609a15dfa],msg = misuse at line 106271 of [8609a15dfa],db=/data/data/de.l_one.app.shaufel/databases/poidatabase