从Sd卡访问Sqlite数据库

时间:2012-03-02 15:41:35

标签: android database sqlite sd-card

我已将数据库存储在SD卡上,现在我正在尝试访问它,但它给了我一个错误:

 03-02 15:36:09.653: E/AndroidRuntime(27299): FATAL EXCEPTION: main
     03-02 15:36:09.653: E/AndroidRuntime(27299): java.lang.RuntimeException: Unable to start   activity ComponentInfo{com.drturing/com.drturing.ProfileList}: android.database.sqlite.SQLiteException: no such table: FeverQuestionTable: , while compiling: Select * from FeverQuestionTable
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.app.ActivityThread.access$600(ActivityThread.java:122)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.os.Looper.loop(Looper.java:137)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.app.ActivityThread.main(ActivityThread.java:4340)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at java.lang.reflect.Method.invokeNative(Native Method)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at java.lang.reflect.Method.invoke(Method.java:511)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at dalvik.system.NativeStart.main(Native Method)
03-02 15:36:09.653: E/AndroidRuntime(27299): Caused by: android.database.sqlite.SQLiteException: no such table: FeverQuestionTable: , while compiling: Select * from FeverQuestionTable
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:127)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:94)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:53)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1564)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1538)
03-02 15:36:09.653: E/AndroidRuntime(27299):    at com.databasehelper.Developer.getQuestion(Developer.java:62)

1 个答案:

答案 0 :(得分:1)

您正尝试在该数据库中执行查询Select * from FeverQuestionTable,但SQLite数据库不包含名为FeverQuestionTable的表。

如果是新的SQLite数据库,则必须首先执行CREATE TABLE FeverQuestionTable ...,然后执行要创建的列,从而创建该表。

有关详细信息,请参阅SQLite documentation CREATE TABLE