0

下面的sql代码

SQLiteDatabase db = this.getWritableDatabase();

        if(getCartItems(cart.id).size()>0){

            ContentValues values = new ContentValues();

            values.put(COL_ITEM_ID, cart.id);
            values.put(COL_CART_ADDDATE, cart.addDate);
            long re = db.insert(TABLE_NAME_CART, null, values);
            db.close();

            return re > 0;
        }else{
            db.close();
            return false;
        }

此代码返回以下错误:

java.lang.NullPointerException
at android.database.sqlite.SQLiteStatement.releaseAndUnlock(SQLiteStatement.java:290)
at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:115)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1718)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1591)
at phoenix.metro.uis.DBHelper.insertCart(DBHelper.java:120)
at phoenix.metro.uis.SearchActivity$4.onClick(SearchActivity.java:171)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14105)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)

以下代码中的错误:

long re = db.insert(TABLE_NAME_CART, null, values);
4

0 回答 0