Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SQLiteConstraintException不进入内部捕捉_Android_Sqlite_Exception Handling_Insert_Sql Update - Fatal编程技术网

Android SQLiteConstraintException不进入内部捕捉

Android SQLiteConstraintException不进入内部捕捉,android,sqlite,exception-handling,insert,sql-update,Android,Sqlite,Exception Handling,Insert,Sql Update,当我运行数据库中的代码时,插入一个异常: 08-29 15:40:17.519: E/SQLiteDatabase(3599): android.database.sqlite.SQLiteConstraintException: column date is not unique (code 19) 这是正常的,因为我已经把这个值作为键了。 因此,在这种情况下,我捕获了sqliteconstraintextexception,但在运行代码时,我从未进入捕获范围 我做错了什么

当我运行数据库中的代码时,插入一个异常:

08-29 15:40:17.519: E/SQLiteDatabase(3599): android.database.sqlite.SQLiteConstraintException: column date is not unique (code 19)
这是正常的,因为我已经把这个值作为键了。 因此,在这种情况下,我捕获了
sqliteconstraintextexception
,但在运行代码时,我从未进入捕获范围

我做错了什么

           try {
                db.insert(TABLE_STATISTICS, null, values);
            } catch (SQLiteConstraintException e) {
                Log.d("entered", "entered the exception");
                ContentValues valuesUp = new ContentValues();
                valuesUp.put((isMT ? KEY_MT : KEY_MO), change); 
                db.update(TABLE_STATISTICS, valuesUp, KEY_DATE + "=?",
                        new String[] { message_date });
            }
多谢各位

整个日志:

08-29 15:55:55.870: E/SQLiteDatabase(3828): Error inserting MO=0 date=2012-08-08 MT=1
08-29 15:55:55.870: E/SQLiteDatabase(3828): android.database.sqlite.SQLiteConstraintException: column date is not unique (code 19)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:775)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at xx.xxx.xxx.xx.xxxx.StatisticsHolderDay.updateCounterNextStep(StatisticsHolderDay.java:124)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at xx.xxx.xxx.xx.xxxx.StatisticsHolderDay.updateCounter(StatisticsHolderDay.java:102)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at xx.xxx.xxx.xx.xxxx.LastMonthActivity.onStart(LastMonthActivity.java:146)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.app.Activity.performStart(Activity.java:5018)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.os.Looper.loop(Looper.java:137)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at android.app.ActivityThread.main(ActivityThread.java:4745)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at java.lang.reflect.Method.invokeNative(Native Method)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at java.lang.reflect.Method.invoke(Method.java:511)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-29 15:55:55.870: E/SQLiteDatabase(3828):     at dalvik.system.NativeStart.main(Native Method)

请改用
db.insertOrThrow()

是否确定错误来自此插入?请发布整个日志。@iturki用整个日志更新了主要问题。java:124是我插入问题的地方。