0

Here's my app, the AVD starts up but when I try to open the app I get a message

"Your App has stopped working unfortunately"

This is my Logcat details:

Caused by: android.database.sqlite.SQLiteException: near "TABLEproducts": syntax error (code 1): , while compiling: CREATE TABLEproducts(_idINTEGER PRIMARY KEY AUTOINCREMENTproductnameTEXT);

Any help is more than appreciated.

Here is the Code:

public class MyDB extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "store.db";
public static final String  TABLE_PRODUCTS = "products";
public static final String  COLUMN_ID = "_id";
public static final String  COLUMN_PRODUCTNAME = "productname";


public MyDB(Context context, String name, SQLiteDatabase.CursorFactory   factory, int version) {
super(context, DATABASE_NAME, factory, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
 String query = "CREATE TABLE" + TABLE_PRODUCTS + "(" +
        COLUMN_ID + "INTEGER PRIMARY KEY AUTOINCREMENT" +
        COLUMN_PRODUCTNAME + "TEXT" +
                 ");";
 db.execSQL(query);
}

1 Answer 1

2

Put space after TABLE like "CREATE TABLE " and also after every column name.

String query = "CREATE TABLE " + TABLE_PRODUCTS + "(" +
        COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
        COLUMN_PRODUCTNAME + " TEXT " +
                 ");";
Sign up to request clarification or add additional context in comments.

2 Comments

Caused by: android.database.sqlite.SQLiteException: near "productnameTEXT": syntax error (code 1): , while compiling: CREATE TABLE products( _idINTEGER PRIMARY KEY AUTOINCREMENT productnameTEXT );
try the query I provided

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.