0

我试图在我的笔记本电脑上更改我的一些文件名,我一定是把我的程序搞砸了。该程序运行良好,直到它需要打开 SQLite 数据库时,它崩溃了。

它曾经工作正常,所以它与我更改一些文件名有关。我以为我到处都修好了,但肯定没有。我尝试更新数据库的版本号,但没有帮助。

先感谢您!

高分.java

dh.openDB();  //Line 30

数据库助手.java

public SQLiteDatabase openDB() {
    db = this.getWritableDatabase();  //Line 32
    return db;
}

LogCat 输出

01-22 13:56:35.454: E/AndroidRuntime(9641): FATAL EXCEPTION: main
01-22 13:56:35.454: E/AndroidRuntime(9641): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bibletrivia/com.example.bibletrivia.Highscores}: android.database.sqlite.SQLiteException: near "DB_TABLE": syntax error (code 1): , while compiling: CREATE DB_TABLE HighscoresList (_id INTEGER PRIMARY KEY AUTOINCREMENT,score LONG,percentage INTEGER,category STRING,total_score LONG);
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.os.Looper.loop(Looper.java:137)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.app.ActivityThread.main(ActivityThread.java:5039)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at java.lang.reflect.Method.invokeNative(Native Method)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at java.lang.reflect.Method.invoke(Method.java:511)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at dalvik.system.NativeStart.main(Native Method)
01-22 13:56:35.454: E/AndroidRuntime(9641): Caused by: android.database.sqlite.SQLiteException: near "DB_TABLE": syntax error (code 1): , while compiling: CREATE DB_TABLE HighscoresList (_id INTEGER PRIMARY KEY AUTOINCREMENT,score LONG,percentage INTEGER,category STRING,total_score LONG);
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at com.example.bibletrivia.DatabaseHelper.onCreate(DatabaseHelper.java:148)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at com.example.bibletrivia.DatabaseHelper.openDB(DatabaseHelper.java:32)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at com.example.bibletrivia.Highscores.onCreate(Highscores.java:30)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.app.Activity.performCreate(Activity.java:5104)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-22 13:56:35.454: E/AndroidRuntime(9641):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-22 13:56:35.454: E/AndroidRuntime(9641):     ... 11 more
4

2 回答 2

3
Caused by: android.database.sqlite.SQLiteException: near "DB_TABLE": syntax error (code 1): , while compiling: CREATE DB_TABLE HighscoresList (_id INTEGER PRIMARY KEY AUTOINCREMENT,score LONG,percentage INTEGER,category STRING,total_score LONG);

将 DB_TABLE 更改为“表”

你应该总是仔细查看 logcat,因为你可以很容易地找到你的错误。找到异常后,您应该很容易找到解决方法。

于 2013-02-04T19:47:50.290 回答
1
CREATE DB_TABLE HighscoresList

应该:

CREATE TABLE HighscoresList

阅读创建表语法

于 2013-02-04T19:47:43.920 回答