使用SQLite的Todo列表

时间:2014-03-05 19:23:17

标签: android sqlite fragment

我按照谷歌的教程将todo列表添加到我的应用中。我有databasehelper类和todolist片段类以及todolist模型。不幸的是,当我运行应用程序时它停止工作。我没有任何错误,我不确定哪个部分我做错了

logcat的

03-05 19:01:57.367: I/BLAH(26508): the project is com.projecttracker.model.TheProject@41ee07a8
03-05 19:01:57.377: I/PROJECT_ITEM_FRAG(26508): getAllProjects add project one with id 1
03-05 19:01:59.229: E/SQLiteLog(26508): (1) near "FROMTodo": syntax error
03-05 19:01:59.229: D/AndroidRuntime(26508): Shutting down VM
03-05 19:01:59.229: W/dalvikvm(26508): threadid=1: thread exiting with uncaught exception (group=0x415e7ba8)
03-05 19:01:59.229: E/AndroidRuntime(26508): FATAL EXCEPTION: main
03-05 19:01:59.229: E/AndroidRuntime(26508): Process: com.projecttracker, PID: 26508
03-05 19:01:59.229: E/AndroidRuntime(26508): android.database.sqlite.SQLiteException: near "FROMTodo": syntax error (code 1): , while compiling: SELECT * FROMTodo
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at com.projecttracker.model.DatabaseHelper.getAllTodolists(DatabaseHelper.java:112)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at com.projecttracker.TodolistFragment.onCreateView(TodolistFragment.java:46)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.os.Handler.handleCallback(Handler.java:733)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.os.Handler.dispatchMessage(Handler.java:95)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.os.Looper.loop(Looper.java:136)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at android.app.ActivityThread.main(ActivityThread.java:5017)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at java.lang.reflect.Method.invokeNative(Native Method)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at java.lang.reflect.Method.invoke(Method.java:515)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-05 19:01:59.229: E/AndroidRuntime(26508):    at dalvik.system.NativeStart.main(Native Method)
03-05 19:02:01.261: I/Process(26508): Sending signal. PID: 26508 SIG: 9
03-05 19:11:18.544: I/Adreno-EGL(27649): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
03-05 19:11:18.574: D/OpenGLRenderer(27649): Enabling debug mode 0
03-05 19:11:18.624: D/dalvikvm(27649): GC_FOR_ALLOC freed 154K, 2% free 9359K/9544K, paused 15ms, total 15ms
03-05 19:11:25.361: I/BLAH(27649): the project is com.projecttracker.model.TheProject@41ede950
03-05 19:11:25.371: I/PROJECT_ITEM_FRAG(27649): getAllProjects add project one with id 1
03-05 19:11:32.658: E/SQLiteLog(27649): (1) near "FROMTodo": syntax error
03-05 19:11:32.658: D/AndroidRuntime(27649): Shutting down VM
03-05 19:11:32.658: W/dalvikvm(27649): threadid=1: thread exiting with uncaught exception (group=0x415e7ba8)
03-05 19:11:32.668: E/AndroidRuntime(27649): FATAL EXCEPTION: main
03-05 19:11:32.668: E/AndroidRuntime(27649): Process: com.projecttracker, PID: 27649
03-05 19:11:32.668: E/AndroidRuntime(27649): android.database.sqlite.SQLiteException: near "FROMTodo": syntax error (code 1): , while compiling: SELECT * FROMTodo
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at com.projecttracker.model.DatabaseHelper.getAllTodolists(DatabaseHelper.java:112)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at com.projecttracker.TodolistFragment.onCreateView(TodolistFragment.java:41)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.os.Handler.handleCallback(Handler.java:733)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.os.Handler.dispatchMessage(Handler.java:95)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.os.Looper.loop(Looper.java:136)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at android.app.ActivityThread.main(ActivityThread.java:5017)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at java.lang.reflect.Method.invokeNative(Native Method)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at java.lang.reflect.Method.invoke(Method.java:515)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-05 19:11:32.668: E/AndroidRuntime(27649):    at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:2)

这是语法错误,FROMTodo。您需要FROMTodo之间的空格。

错误说

   靠近“FROMTodo”:语法错误

在收盘价之前添加空格:

 String selectQuery = "SELECT * FROM "+ todoTable
                                    ^
                                    |-- Space here