我试图改变我笔记本电脑上的一些文件名,但我必须搞砸了我的程序。程序运行正常,直到它到达需要打开SQLite数据库的程度,它崩溃了。
它曾经工作正常,所以它与我改变一些文件名有关。我以为我到处去修理它但它一定没有。我尝试更新数据库的版本号,但没有帮助。
提前谢谢!
Highscores.java
dh.openDB(); //Line 30
DatabaseHelper.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
答案 0 :(得分: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更改为“table”
你应该总是仔细看看logcat,因为你可以很容易地找到你的错误。找到异常后,您应该很容易找到解决方法。
答案 1 :(得分:1)