SQLite syntax error

0 Liandy Hardikoesoemo · August 2, 2015
Hi guys, I'm currently stuck on tutorial 54 since I got a syntax error on my code:



    java.lang.RuntimeException: Unable to start activity ComponentInfo{...}: android.database.sqlite.SQLiteException: near "productname": syntax error (code 1): , while compiling: CREATE TABLE products(_id INTEGER PRIMARY KEY AUTOINCREMENT productname TEXT );


Here's my current code:


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

// more code

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

}

// more code


Can anyone help me with this? :)

Post a Reply

Replies

Oldest  Newest  Rating
0 Payoj Baral · August 3, 2015
Try putting a comma between AUTOINCREMENT and productname.
  • 1

Java / Android Development

107,014 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator