I tried to alter some of my file names on my laptop and I must have screwed something up with my program. The program runs fine until when it gets to the point where it needs to open the SQLite database, it crashes.
It used to work fine so it has something to do with me changing some file names. I thought I went everywhere and fixed it but it must not have. I tried updating the version number of the db but it did not help.
Thank you in advance!
Highscores.java
dh.openDB(); //Line 30
DatabaseHelper.java
public SQLiteDatabase openDB() {
db = this.getWritableDatabase(); //Line 32
return db;
}
LogCat output
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);
change DB_TABLE to "table"
You should always look carfully at logcat, because you can find your error easily their. Once you found the Exception, you should easily find how to solve it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.