相关代码如下:
private static final String SQL_CREATE_ENTRIES = "CREATE TABLE "
+ RingoContract.Config.TABLE_NAME
+ " ("
+ RingoContract.Config._ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ RingoContract.Config.COLUMN_NAME_KEY
+ " TEXT NOT NULL, "
+ RingoContract.Config.COLUMN_NAME_VALUES
+ " TEXT NOT NULL);";
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(SQL_CREATE_ENTRIES);
}
报错如下:
02-28 08:28:09.926: E/SQLiteLog(25941): (1) near "values": syntax error
02-28 08:28:09.946: E/AndroidRuntime(25941): FATAL EXCEPTION: main
02-28 08:28:09.946: E/AndroidRuntime(25941): Process: com.wm5l.ringo, PID: 25941
02-28 08:28:09.946: E/AndroidRuntime(25941): android.database.sqlite.SQLiteException: near "values": syntax error (code 1): , while compiling: CREATE TABLE config (_id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT NOT NULL, values TEXT NOT NULL);
02-28 08:28:09.946: E/AndroidRuntime(25941): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
02-28 08:28:09.946: E/AndroidRuntime(25941): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
02-28 08:28:09.946: E/AndroidRuntime(25941): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
02-28 08:28:09.946: E/AndroidRuntime(25941): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
02-28 08:28:09.946: E/AndroidRuntime(25941): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
02-28 08:28:09.946: E/AndroidRuntime(25941): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
02-28 08:28:09.946: E/AndroidRuntime(25941): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1674)
02-28 08:28:09.946: E/AndroidRuntime(25941): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)
02-28 08:28:09.946: E/AndroidRuntime(25941): at com.wm5l.ringo.database.RingoDbHelper.onCreate(RingoDbHelper.java:30)
02-28 08:28:09.946: E/AndroidRuntime(25941): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
02-28 08:28:09.946: E/AndroidRuntime(25941): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
02-28 08:28:09.946: E/AndroidRuntime(25941): at com.wm5l.ringo.activity.LoginActivity.saveNamePass(LoginActivity.java:97)
02-28 08:28:09.946: E/AndroidRuntime(25941): at com.wm5l.ringo.activity.LoginActivity.access$3(LoginActivity.java:95)
02-28 08:28:09.946: E/AndroidRuntime(25941): at com.wm5l.ringo.activity.LoginActivity$1.onResponse(LoginActivity.java:81)
02-28 08:28:09.946: E/AndroidRuntime(25941): at com.wm5l.ringo.activity.LoginActivity$1.onResponse(LoginActivity.java:1)
02-28 08:28:09.946: E/AndroidRuntime(25941): at com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:65)
02-28 08:28:09.946: E/AndroidRuntime(25941): at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
02-28 08:28:09.946: E/AndroidRuntime(25941): at android.os.Handler.handleCallback(Handler.java:733)
02-28 08:28:09.946: E/AndroidRuntime(25941): at android.os.Handler.dispatchMessage(Handler.java:95)
02-28 08:28:09.946: E/AndroidRuntime(25941): at android.os.Looper.loop(Looper.java:149)
02-28 08:28:09.946: E/AndroidRuntime(25941): at android.app.ActivityThread.main(ActivityThread.java:5257)
02-28 08:28:09.946: E/AndroidRuntime(25941): at java.lang.reflect.Method.invokeNative(Native Method)
02-28 08:28:09.946: E/AndroidRuntime(25941): at java.lang.reflect.Method.invoke(Method.java:515)
02-28 08:28:09.946: E/AndroidRuntime(25941): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-28 08:28:09.946: E/AndroidRuntime(25941): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
02-28 08:28:09.946: E/AndroidRuntime(25941): at dalvik.system.NativeStart.main(Native Method)
------解决思路----------------------
明显的sql语句有问题,单独执行下CREATE TABLE config (_id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT NOT NULL, values TEXT NOT NULL);看看什么错误