Android 2.3.3 Eclipse Version: 3.7.0 LogCat
?LogCat? 报错信息:
03-13 10:25:37.163: ERROR/AndroidRuntime(4166): java.lang.IllegalArgumentException: the bind value at index 2 is null 03-13 10:25:37.163: ERROR/AndroidRuntime(4166): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:237) 03-13 10:25:37.163: ERROR/AndroidRuntime(4166): at android.database.sqlite.SQLiteQuery.bindString(SQLiteQuery.java:185) 03-13 10:25:37.163: ERROR/AndroidRuntime(4166): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:48) 03-13 10:25:37.163: ERROR/AndroidRuntime(4166): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356) 03-13 10:25:37.163: ERROR/AndroidRuntime(4166): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1235) 03-13 10:25:37.163: ERROR/AndroidRuntime(4166): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1189) 03-13 10:25:37.163: ERROR/AndroidRuntime(4166): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1271) 03-13 10:25:37.163: ERROR/AndroidRuntime(4166): at com.tmall.nokia.db.RecordDBHelper.query(RecordDBHelper.java:53) 03-13 10:25:37.163: ERROR/AndroidRuntime(4166): at com.tmall.nokia.manage.RecordDBopt.get(RecordDBopt.java:80) 03-13 10:25:37.163: ERROR/AndroidRuntime(4166): at com.tmall.nokia.Play.savePlayCount(Play.java:775) 03-13 10:25:37.163: ERROR/AndroidRuntime(4166): at com.tmall.nokia.Play$5.run(Play.java:369) 03-13 10:25:37.163: ERROR/AndroidRuntime(4166): at java.util.Timer$TimerImpl.run(Timer.java:284)
?
发生错误原因分析:
检查相关代码,发现
传入savePlayCount的String值programid为null,在传入之前和传入后均未作判断
public void savePlayCount(String programid, int count) { …… }
?
而programid最终作为参数args这个String数组中的一个值,用于数据库查询
Cursor cur = db.query(TBL_NAME, null, where, args, null, null, order);
?
由于args这个String数组中的String有null值,报错
?
解决办法:
在传入programid前或之后对其值作判断
if (programid != null) { …… }
?
PS:args这个String数组中不能有null值