0

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
1
  • 5
    Try using TABLE instead of DB_TABLE in your create table query. Commented Feb 4, 2013 at 19:47

2 Answers 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);

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.

Sign up to request clarification or add additional context in comments.

Comments

1
CREATE DB_TABLE HighscoresList

should be:

CREATE TABLE HighscoresList

Read create table syntax.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.