我试图更改笔记本电脑上的某些文件名,并且我的程序一定搞砸了。该程序可以正常运行,直到到达需要打开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
最佳答案
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,因为您可以轻松地找到它们的错误。找到异常后,您应该很容易找到解决方法。