DBhelper dbHelper = new DBhelper(this);
mDatabase = dbHelper.getWritableDatabase();
我的dbcontract的代码是:
public final class DBcontract {
private DBcontract(){}
public static class DB_table1 implements BaseColumns {
public static final String TABLE_Name = "Timer_table";
public static final String COL_1 = "id";
public static final String COL_2 = "Title";
public static final String COL_3 = "Startvalue";
public static final String COL_4 = "Endvalue";
public static final String COL_5 = "Timer";
}
}
dbhelper是:
public class DBhelper extends SQLiteOpenHelper {
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "archeage.db";
//Create table query
public static final String CREATE_TABLE =
"" + "CREATE TABLE " + TABLE_Name + " ( "
+ DBcontract.DB_table1.COL_1 + " INTEGER PRIMARY KEY AUTO_INCREMENT, "
+ DBcontract.DB_table1.COL_2 + " TEXT NOT NULL, "
+ DBcontract.DB_table1.COL_3 + " INTEGER NOT NULL, "
+ DBcontract.DB_table1.COL_4 + " INTEGER NOT NULL, "
+ DBcontract.DB_table1.COL_5 + " INTEGER NOT NULL"
+ ");";
//delete table query
public static final String DELETE_TABLE = "DROP TABLE IF EXISTS " + TABLE_Name;
public DBhelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(DELETE_TABLE);
onCreate(db);
}
}
编辑logcat错误:
04-09 13:27:51.233 28939-28939/com.example.xang.archeage E/SQLiteLog: (1) near "AUTO_INCREMENT": syntax error
04-09 13:27:51.236 28939-28939/com.example.xang.archeage E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.xang.archeage, PID: 28939
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.xang.archeage/com.example.xang.archeage.Timerpopup}: android.database.sqlite.SQLiteException: near "AUTO_INCREMENT": syntax error (code 1): , while compiling: CREATE TABLE Timer_table ( id INTEGER PRIMARY KEY AUTO_INCREMENT, Title TEXT NOT NULL, Startvalue INTEGER NOT NULL, Endvalue INTEGER NOT NULL, Timer INTEGER NOT NULL);
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2779)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2844)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6361)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: android.database.sqlite.SQLiteException: near "AUTO_INCREMENT": syntax error (code 1): , while compiling: CREATE TABLE Timer_table ( id INTEGER PRIMARY KEY AUTO_INCREMENT, Title TEXT NOT NULL, Startvalue INTEGER NOT NULL, Endvalue INTEGER NOT NULL, Timer INTEGER NOT NULL);
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:898)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:509)
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:1699)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1630)
at com.example.xang.archeage.DBhelper.onCreate(DBhelper.java:41)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at com.example.xang.archeage.Timerpopup.onCreate(Timerpopup.java:27)
at android.app.Activity.performCreate(Activity.java:6675)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2732)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2844)Â
at android.app.ActivityThread.-wrap12(ActivityThread.java)Â
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572)Â
at android.os.Handler.dispatchMessage(Handler.java:110)Â
at android.os.Looper.loop(Looper.java:203)Â
at android.app.ActivityThread.main(ActivityThread.java:6361)Â
at java.lang.reflect.Method.invoke(Native Method)Â
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)Â
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)Â