08-02 16:26:24.750: E/Database(28841): Error inserting data
08-02 16:26:24.750: E/Database(28841): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
08-02 16:26:24.750: E/Database(28841): at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
08-02 16:26:24.750: E/Database(28841): at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:61)
08-02 16:26:24.750: E/Database(28841): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1584)
08-02 16:26:24.750: E/Database(28841): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1428)
08-02 16:26:24.750: E/Database(28841): at com.app.android.DataOperations.insertItems(DataOperations.java:69)
08-02 16:26:24.750: E/Database(28841): at com.app.android.DownloadTask.createDatabase(DownloadTask.java:173)
08-02 16:26:24.750: E/Database(28841): at com.app.android.DownloadTask.doInBackground(DownloadTask.java:59)
08-02 16:26:24.750: E/Database(28841): at com.app.android.DownloadTask.doInBackground(DownloadTask.java:1)
08-02 16:26:24.750: E/Database(28841): at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-02 16:26:24.750: E/Database(28841): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
08-02 16:26:24.750: E/Database(28841): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
08-02 16:26:24.750: E/Database(28841): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
08-02 16:26:24.750: E/Database(28841): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
08-02 16:26:24.750: E/Database(28841): at java.lang.Thread.run(Thread.java:1019)
以上是我的 LogCat 报告。我想做的是插入数据。查看logcat后,我发现这是违反约束的。我试图把我的代码:
public void insert(...){
long insertID = 0;
try{
Log.i("DataOperation", String.valueOf(insertID));
insertID = sqllitedb.insert(DBase.TABLE_NAME, null, contentValues);
}catch(android.database.sqlite.SQLiteException ex){
Log.i("dataops_", "Error Constraint"); //Print
}
}
什么都没有发生..我的 logcat 充满了堆栈跟踪。没有注释的行符号(见上文)。
怎么可能处理。注意在我的整个程序中只有一个插入语句(上面)。测试确定,然后我将继续。
还告诉我如何处理我的数据库是否已创建/已经存在,这样如果存在我就不会运行我的 DownloadTask。