0

我无法理解这个错误,在我的更新命令中,我有 10 个字段要更新,但是出现了这个错误09-17 17:18:25.234: E/AndroidRuntime(4929): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jpos/com.sys.Main}: java.lang.IllegalArgumentException: the bind value at index 11 is null

它表示索引 11 为空,但在我的表中作为字段的总列是 10。

09-17 17:18:25.203: W/dalvikvm(4929): threadid=1: thread exiting with uncaught exception (group=0x40015560)
09-17 17:18:25.234: E/AndroidRuntime(4929): FATAL EXCEPTION: main
09-17 17:18:25.234: E/AndroidRuntime(4929): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jpos/com.sys.Main}: java.lang.IllegalArgumentException: the bind value at index 11 is null
09-17 17:18:25.234: E/AndroidRuntime(4929):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at android.os.Looper.loop(Looper.java:123)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at android.app.ActivityThread.main(ActivityThread.java:3647)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at java.lang.reflect.Method.invokeNative(Native Method)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at java.lang.reflect.Method.invoke(Method.java:507)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at dalvik.system.NativeStart.main(Native Method)
09-17 17:18:25.234: E/AndroidRuntime(4929): Caused by: java.lang.IllegalArgumentException: the bind value at index 11 is null
09-17 17:18:25.234: E/AndroidRuntime(4929):     at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:237)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1701)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1636)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at com.jpos.classes.jposDbHelperHashMap.updateTableMunicipality(DbHelperHashMap.java:103)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at com.jpos.JPOSMain.UpdateTableMunicipalityCodes(JPOSMain.java:146)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at com.jpos.JPOSMain.onCreate(JPOSMain.java:115)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-17 17:18:25.234: E/AndroidRuntime(4929):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
09-17 17:18:25.234: E/AndroidRuntime(4929):     ... 11 more

这是我的更新命令

 private void UpdateTableMunicipalityCodes() {
        HashMap<String, String> queryValues =  new  HashMap<String, String>();

        queryValues.put("munc_id", "7");
        queryValues.put("rdo_code", "999" );
        queryValues.put("munc_code", "999");
        queryValues.put("munc_desc", "UPDATECOMMAND");
        queryValues.put("area_code", "999");
        queryValues.put("created_date", "2013-17-2013 06:02:29");
        queryValues.put("created_by", "SYSGENn");
        queryValues.put("last_modified_date", "2013-17-2013 07:02:09");
        queryValues.put("last_modified_by", "SYSGENn");
        queryValues.put("munc_status", "A");
        hashDbHelper.updateTableMunicipality(queryValues);

      }

要通过这里:

public void updateTableMunicipality(HashMap<String, String> queryValues) 
{ 
        database = this.getWritableDatabase();  
        ContentValues values = new ContentValues();
        values.put("MUNC_ID", queryValues.get("munc_id"));
        values.put("RDO_CODE", queryValues.get("rdo_code"));
        values.put("MUNC_CODE", queryValues.get("munc_code"));
        values.put("MUNC_DESC", queryValues.get("munc_desc"));
        values.put("AREA_CODE", queryValues.get("area_code"));
        values.put("CREATED_DATE", queryValues.get("created_date"));
        values.put("CREATED_BY", queryValues.get("created_by"));
        values.put("LAST_MODIFIED_DATE", queryValues.get("last_modified_date"));
        values.put("LAST_MODIFIED_BY", queryValues.get("last_modified_by"));
        values.put("MUNC_STATUS", queryValues.get("munc_status"));      
        database.update("tbl_municipality_codes", values, "MUNC_ID" + " = ?",     newString[] { queryValues.get("MUNC_ID") });
        System.out.println("Updated " + queryValues.get("munc_id"));        
      }

这是我的创建表查询

    query ="CREATE TABLE [tbl_municipality_codes] (" +
              "[MUNC_ID] [INT(1000)] NOT NULL," +
              "[RDO_CODE] [VARCHAR(50)] NOT NULL," +
              "[MUNC_CODE] [VARCHAR(50)] NOT NULL, " +
              "[MUNC_DESC] [VARCHAR(100)] NOT NULL, "+
              "[AREA_CODE] VARCHAR, "+
              "[CREATED_DATE] DATETIME NOT NULL," +
              "[CREATED_BY] [VARCHAR(50)] NOT NULL, "+
             "[LAST_MODIFIED_DATE] DATETIME," +
              "[LAST_MODIFIED_BY] [VARCHAR(50)],"+
              "[MUNC_STATUS] [VARCHAR(1)] NOT NULL,"+
              "CONSTRAINT [sqlite_autoindex_tbl_municipality_codes_1] PRIMARY KEY ([MUNC_ID]))";

我认为我的错误出在表中的约束自动索引器中。我该如何解决?

4

1 回答 1

1

您正在尝试从您的条目中读取HashMap不存在的条目,因此您得到null

queryValues.put("munc_id", "7");
...
database.update(..., newString[] { queryValues.get("MUNC_ID") });

正如muratgu 所说,您必须使用queryValues.get("munc_id").

于 2013-09-17T06:52:23.530 回答