晚上好!
我正在尝试从我刚刚在我的 android 项目中创建的 SQLite 数据库中读取数据。我创建数据库并输入数据没有任何问题(我认为)。我查询数据库以获取没有任何运行时投诉的数据,并且我得到了从方法调用返回的游标。但是当我尝试使用光标时应用程序崩溃了。“线程以未捕获的异常退出 (group=0x416b72a0)。
这是我要运行的代码。光标的 toString 工作正常。
TransactionSQLOH helper = new TransactionSQLOH(context, getDbName(yearS, monthS));
SQLiteDatabase db = helper.getReadableDatabase();
String[] columns = {"amount", "label", "year", "month", "day", "categoryID", "type", "ID", "time"};
Cursor cursor = db.query(TransactionSQLOH.TABLE_NAME, columns, null, null, null, null, null);
System.out.println(db);
helper.close();
System.out.println("Transaction_Check3.1");
if (cursor == null){
return null;
}
System.out.println("Transaction_Check3.2");
System.out.println(cursor);
int test = cursor.getCount();
System.out.println("Transaction_Check3.3");
Transaction[] result = new Transaction[10];
我在线上遇到错误
int test = cursor.getCount();
帮助将不胜感激:)
编辑,记录:
02-19 21:08:11.273: I/System.out(21558): Transaction_Check1
02-19 21:08:11.283: I/System.out(21558): Transaction_Check2
02-19 21:08:11.283: I/System.out(21558): SQLiteDatabase: /data/data/com.SverkerSbrg.Spendo/databases/transactions_201301
02-19 21:08:11.283: I/System.out(21558): Transaction_Check3
02-19 21:08:11.288: I/System.out(21558): Transaction_Check3.1
02-19 21:08:11.288: I/System.out(21558): Transaction_Check3.2
02-19 21:08:11.288: I/System.out(21558): android.database.sqlite.SQLiteCursor@421107d8
02-19 21:08:11.288: I/System.out(21558): Transaction_Check3.3
02-19 21:08:11.288: I/System.out(21558): Transaction_Check4
02-19 21:08:11.288: D/AndroidRuntime(21558): Shutting down VM
02-19 21:08:11.288: W/dalvikvm(21558): threadid=1: thread exiting with uncaught exception (group=0x416b72a0)
02-19 21:08:11.328: E/AndroidRuntime(21558): FATAL EXCEPTION: main
02-19 21:08:11.328: E/AndroidRuntime(21558): java.lang.IllegalStateException: Could not execute method of the activity
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.view.View$1.onClick(View.java:3704)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.view.View.performClick(View.java:4232)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.view.View$PerformClick.run(View.java:17298)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.os.Handler.handleCallback(Handler.java:615)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.os.Handler.dispatchMessage(Handler.java:92)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.os.Looper.loop(Looper.java:137)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.app.ActivityThread.main(ActivityThread.java:4921)
02-19 21:08:11.328: E/AndroidRuntime(21558): at java.lang.reflect.Method.invokeNative(Native Method)
02-19 21:08:11.328: E/AndroidRuntime(21558): at java.lang.reflect.Method.invoke(Method.java:511)
02-19 21:08:11.328: E/AndroidRuntime(21558): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
02-19 21:08:11.328: E/AndroidRuntime(21558): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
02-19 21:08:11.328: E/AndroidRuntime(21558): at dalvik.system.NativeStart.main(Native Method)
02-19 21:08:11.328: E/AndroidRuntime(21558): Caused by: java.lang.reflect.InvocationTargetException
02-19 21:08:11.328: E/AndroidRuntime(21558): at java.lang.reflect.Method.invokeNative(Native Method)
02-19 21:08:11.328: E/AndroidRuntime(21558): at java.lang.reflect.Method.invoke(Method.java:511)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.view.View$1.onClick(View.java:3699)
02-19 21:08:11.328: E/AndroidRuntime(21558): ... 11 more
02-19 21:08:11.328: E/AndroidRuntime(21558): Caused by: java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:972)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:609)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:349)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:834)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:143)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:196)
02-19 21:08:11.328: E/AndroidRuntime(21558): at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:236)
02-19 21:08:11.328: E/AndroidRuntime(21558): at com.SverkerSbrg.Spendo.Datastructures.Transaction.getMonthTransaciton(Transaction.java:88)
02-19 21:08:11.328: E/AndroidRuntime(21558): at com.SverkerSbrg.Spendo.MainActivity.btn2_click(MainActivity.java:43)
02-19 21:08:11.328: E/AndroidRuntime(21558): ... 14 more