SqLite的query方法,参数args中不能含null值

Android 2.3.3 
Eclipse Version: 3.7.0 
LogCat  


LogCat  报错信息:

03-13 11:37:27.419: ERROR/AndroidRuntime(844): java.lang.IllegalArgumentException: the bind value at index 2 is null
03-13 11:37:27.419: ERROR/AndroidRuntime(844): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:237)
03-13 11:37:27.419: ERROR/AndroidRuntime(844): at android.database.sqlite.SQLiteQuery.bindString(SQLiteQuery.java:185)
03-13 11:37:27.419: ERROR/AndroidRuntime(844): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:48)
03-13 11:37:27.419: ERROR/AndroidRuntime(844): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
03-13 11:37:27.419: ERROR/AndroidRuntime(844): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1235)
03-13 11:37:27.419: ERROR/AndroidRuntime(844): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1189)
03-13 11:37:27.419: ERROR/AndroidRuntime(844): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1271)
03-13 11:37:27.419: ERROR/AndroidRuntime(844): at com.taobao.htc.db.RecordDBHelper.query(RecordDBHelper.java:53)
03-13 11:37:27.419: ERROR/AndroidRuntime(844): at com.taobao.htc.manage.RecordDBopt.get(RecordDBopt.java:80)
03-13 11:37:27.419: ERROR/AndroidRuntime(844): at com.taobao.htc.Play.savePlayCount(Play.java:775)
03-13 11:37:27.419: ERROR/AndroidRuntime(844): at com.taobao.htc.Play$5.run(Play.java:369)
03-13 11:37:27.419: ERROR/AndroidRuntime(844): at java.util.Timer$TimerImpl.run(Timer.java:284)


发生错误原因分析:

检查相关代码,发现

传入savePlayCount的String值programid为null,在传入之前和传入后均未作判断

	public void savePlayCount(String programid, int count) {
	……
	}
而programid最终作为参数args这个数组中的一个值,用于数据库查询 
	Cursor cur = db.query(TBL_NAME, null, where, args, null, null, order);


由于args这个String数组中的String有null值,报错

 

解决办法:

在传入programid前或之后对其值作判断

if (programid != null) {
	……
}


 PS:args这个String数组中不能有null值

你可能感兴趣的:(eclipse,android,sqlite,String,null,query)