我设置值并插入数据库,但我在logcat.why
中遇到以下错误03-25 17:41:23.802: E/SQLiteDatabase(10095): Error inserting devicename=iname alarm=ON uuid=00000000-5f53-54ae-5f53-54ae00000000 light=ON
03-25 17:41:23.802: E/SQLiteDatabase(10095): android.database.sqlite.SQLiteConstraintException: column uuid is not unique (code 19)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:782)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at com.iname.bpowerbank.DataBaseAdapter.insertData(DataBaseAdapter.java:97)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at com.iname.bpowerbank.EditPreview.onCreate(EditPreview.java:68)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.app.Activity.performCreate(Activity.java:5231)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.os.Handler.dispatchMessage(Handler.java:102)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.os.Looper.loop(Looper.java:136)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at java.lang.reflect.Method.invokeNative(Native Method)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at java.lang.reflect.Method.invoke(Method.java:515)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-25 17:41:23.802: E/SQLiteDatabase(10095): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
答案 1 :(得分:0)
有两种可能的修复方法,
1. Remove UNIQUE or PRIMARY KEY property for the column "uuid"
或
2. use INSERT OR REPLACE INTO table_name (UUID,name) VALUES ('uuid_value','name_value')