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

前端之家收集整理的这篇文章主要介绍了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,order);


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

解决办法:

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

if (programid != null) {
	……
}


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

猜你在找的Sqlite相关文章