简体   繁体   中英

Android - sqlite inserting error

I'm facing this problem while inserting rows to sqlite :

06-29 11:03:06.025: E/SQLiteDatabase(19205): Error inserting content=null position=9 id=158823 title=Hà Đông thu gần 160 tỷ đồng từ đấu giá quyền sử dụng đất trong đợt 2 source=Thời báo Ngân hàng - 54 phút trước nextpage=2 page=44 publishedDate=2014-06-29 10:09:04 catid=0 thumb=http://images3.baomoi.com/226/148/14183763.aspx
06-29 11:03:06.025: E/SQLiteDatabase(19205): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at android.database.sqlite.SQLiteStatement.native_executeInsert(Native Method)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:113)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1718)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1591)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at com.tornado.docbaomoi.db.ArticlesDB.insert(ArticlesDB.java:64)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at com.tornado.docbaomoi.ui.MainFragment$JSONParse.onPostExecute(MainFragment.java:114)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at com.tornado.docbaomoi.ui.MainFragment$JSONParse.onPostExecute(MainFragment.java:1)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at android.os.AsyncTask.finish(AsyncTask.java:602)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at android.os.AsyncTask.access$600(AsyncTask.java:156)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at android.os.Looper.loop(Looper.java:137)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at android.app.ActivityThread.main(ActivityThread.java:4424)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at java.lang.reflect.Method.invokeNative(Native Method)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at java.lang.reflect.Method.invoke(Method.java:511)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:592)
06-29 11:03:06.025: E/SQLiteDatabase(19205):    at dalvik.system.NativeStart.main(Native Method)

What should I do to solve this ?

Error inserting content=null

This means you have a column that's set to be not NULL, but you didn't supply a value for it. You must supply a value for any column that has a not NULL constraint.

To add to what Gabe said,

You can also replace the value with a whitespace in case its null and add this check to all values being inserted :

if(value == null) {
    value = " ";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM