Click here to Skip to main content
15,889,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
So, I decided to create an application with sqlite database. Then put an add button but when click on it, I have a message("The app has stopped working"). Below I gonna give logcat details:
03-04 11:35:09.210 17673-17673/com.a00003454.tyreshopapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                           Process: com.a00003454.tyreshopapp, PID: 17673
                                                                           java.lang.RuntimeException: Unable to start activity ComponentInfo{com.a00003454.tyreshopapp/com.a00003454.tyreshopapp.AllTyresActivity}: android.database.sqlite.SQLiteException: near "table": syntax error (code 1): , while compiling: CREATE TABLE Tyre.table(ID INTEGER PRIMARY KEY AUTOINCREMENT, TyreBrand TEXT Size INTEGER Cost INTEGER );
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                               at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                               at android.os.Looper.loop(Looper.java:148)
                                                                               at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                            Caused by: android.database.sqlite.SQLiteException: near "table": syntax error (code 1): , while compiling: CREATE TABLE Tyre.table(ID INTEGER PRIMARY KEY AUTOINCREMENT, TyreBrand TEXT Size INTEGER Cost INTEGER );
                                                                               at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                                                                               at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
                                                                               at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
                                                                               at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
                                                                               at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
                                                                               at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
                                                                               at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1674)
                                                                               at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)
                                                                               at com.a00003454.tyreshopapp.TyreDatabaseHelper.onCreate(TyreDatabaseHelper.java:33)
                                                                               at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
                                                                               at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
                                                                               at com.a00003454.tyreshopapp.TyreDatabaseHelper.select(TyreDatabaseHelper.java:59)
                                                                               at com.a00003454.tyreshopapp.AllTyresActivity.onCreate(AllTyresActivity.java:28)
                                                                               at android.app.Activity.performCreate(Activity.java:6237)
                                                                               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                               at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                               at android.os.Looper.loop(Looper.java:148) 
                                                                               at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                               at java.lang.reflect.Method.invoke(Native Method) 
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
03-04 11:35:12.643 17673-17673/com.a00003454.tyreshopapp I/Process: Sending signal. PID: 17673 SIG: 9


What I have tried:

It seems to me that there is a problem with sql statement and tried to change lots of times but no result and here it is:
String sql = "CREATE TABLE " + Table_Name + "(" +
               COL_1 + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
               COL_2 + " TEXT " +
               COL_3 + " INTEGER " +
               COL_4 + " INTEGER " +
               ");";
Posted
Updated 4-Mar-17 0:48am

1 solution

Check this out: Getting Started with SQLite on Android[^]. BTW, there are missing commas in the sql between cols, e.g.
CREATE TABLE contact (
  id integer PRIMARY KEY,
  first_name text,
  last_name text, 
  email text 
);
 
Share this answer
 
v2
Comments
Mir Usmanov 4-Mar-17 7:25am    
Hey Peter thanks a lot for your link. In truth I wanted to create crud sqlite database with the ability to put data into listview. Is there any way for you to help me with that or give a link to some videos or something like that.
Peter Leow 4-Mar-17 10:47am    
This is a new question, so post it as a new question with your code and any issues on implementing listview.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900