Android SQLiteException

时间:2015-07-21 16:32:13

标签: android

这是我的应用程序,AVD启动但是当我尝试打开应用程序时收到消息

  

"您的应用程序不幸地停止了工作"

这是我的Logcat详细信息:

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

任何帮助都不仅仅是值得赞赏的。

以下是代码:

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 个答案:

答案 0 :(得分:2)

TABLE "CREATE TABLE "之后以及每个列名之后放置空格。

String query = "CREATE TABLE " + TABLE_PRODUCTS + "(" +
        COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
        COLUMN_PRODUCTNAME + " TEXT " +
                 ");";