我知道这是一个典型的问题,但所有给出的答案都无法解决我的问题。我有一个预先填充的数据库(用sqlitebrowser做),我在我的资产/数据库文件夹下复制,如https://github.com/jgilfelt/android-sqlite-asset-helper手册中的建议。数据库正确打开但它给出了错误,表明没有这样的表。任何帮助都会受到高度赞赏,这真的很令人沮丧。
代码:
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
public class Database extends SQLiteAssetHelper{
private static final String DBNAME = "tirinini";
private static int DBVERSION = 1;
public Database(Context cont){
super(cont, DBNAME, null, DBVERSION);
}
public Cursor getPicture(){
Cursor c;
SQLiteDatabase db = this.getReadableDatabase();
c = db.rawQuery("SELECT image, fonimata FROM parquestionpack1 ORDER BY RAND() LIMIT " + MainMenu.numOfQuestions, null);
c.moveToFirst();
return c;
}
}
在我使用数据库的活动中,我的应用程序崩溃的部分是:
db = new Database(PlayTheGameParents.this);
c1 = db.getPicture();
日志给出了c1 = db.getPicture();并且在c = db.rawQuery(“SELECT image,fonimata FROM parquestionpack1 ORDER BY RAND()LIMIT”+ MainMenu.numOfQuestions,null);
提前谢谢。编辑1: 它只能找到android_metadata表。如果它对任何人有任何帮助。
logcat的:
07-24 11:05:33.007: E/SQLiteLog(11862): (1) no such table: paruestionpack1
07-24 11:05:33.017: D/AndroidRuntime(11862): Shutting down VM
07-24 11:05:33.017: W/dalvikvm(11862): threadid=1: thread exiting with uncaught exception (group=0x414352a0)
07-24 11:05:33.117: E/AndroidRuntime(11862): FATAL EXCEPTION: main
07-24 11:05:33.117: E/AndroidRuntime(11862): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bnspro.leksopaixnidi/com.bnspro.leksopaixnidi.PlayTheGameParents}: android.database.sqlite.SQLiteException: no such table: paruestionpack1 (code 1): , while compiling: SELECT image, fonimata FROM paruestionpack1 LIMIT 10
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.app.ActivityThread.access$700(ActivityThread.java:140)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.os.Looper.loop(Looper.java:137)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.app.ActivityThread.main(ActivityThread.java:4944)
07-24 11:05:33.117: E/AndroidRuntime(11862): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 11:05:33.117: E/AndroidRuntime(11862): at java.lang.reflect.Method.invoke(Method.java:511)
07-24 11:05:33.117: E/AndroidRuntime(11862): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
07-24 11:05:33.117: E/AndroidRuntime(11862): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
07-24 11:05:33.117: E/AndroidRuntime(11862): at dalvik.system.NativeStart.main(Native Method)
07-24 11:05:33.117: E/AndroidRuntime(11862): Caused by: android.database.sqlite.SQLiteException: no such table: paruestionpack1 (code 1): , while compiling: SELECT image, fonimata FROM paruestionpack1 LIMIT 10
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1108)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:681)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:589)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1420)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1267)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1138)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1344)
07-24 11:05:33.117: E/AndroidRuntime(11862): at com.bnspro.leksopaixnidi.DBAction.getPicture(DBAction.java:28)
07-24 11:05:33.117: E/AndroidRuntime(11862): at com.bnspro.leksopaixnidi.PlayTheGameParents.onCreate(PlayTheGameParents.java:55)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.app.Activity.performCreate(Activity.java:5188)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
07-24 11:05:33.117: E/AndroidRuntime(11862): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2085)
07-24 11:05:33.117: E/AndroidRuntime(11862): ... 11 more