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

作者:DebugLog  发布日期:2012-03-13 20:59:22

01.Android 2.3.3  
02.Eclipse Version: 3.7.0  
03.LogCat   
Android 2.3.3
Eclipse Version: 3.7.0
LogCat  

LogCat  报错信息:


01.03-13 11:37:27.419: ERROR/AndroidRuntime(844): java.lang.IllegalArgumentException: the bind value at index 2 is null 
02.03-13 11:37:27.419: ERROR/AndroidRuntime(844): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:237) 
03.03-13 11:37:27.419: ERROR/AndroidRuntime(844): at android.database.sqlite.SQLiteQuery.bindString(SQLiteQuery.java:185) 
04.03-13 11:37:27.419: ERROR/AndroidRuntime(844): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:48) 
05.03-13 11:37:27.419: ERROR/AndroidRuntime(844): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356) 
06.03-13 11:37:27.419: ERROR/AndroidRuntime(844): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1235) 
07.03-13 11:37:27.419: ERROR/AndroidRuntime(844): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1189) 
08.03-13 11:37:27.419: ERROR/AndroidRuntime(844): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1271) 
09.03-13 11:37:27.419: ERROR/AndroidRuntime(844): at com.taobao.htc.db.RecordDBHelper.query(RecordDBHelper.java:53) 
10.03-13 11:37:27.419: ERROR/AndroidRuntime(844): at com.taobao.htc.manage.RecordDBopt.get(RecordDBopt.java:80) 
11.03-13 11:37:27.419: ERROR/AndroidRuntime(844): at com.taobao.htc.Play.savePlayCount(Play.java:775) 
12.03-13 11:37:27.419: ERROR/AndroidRuntime(844): at com.taobao.htc.Play$5.run(Play.java:369) 
13.03-13 11:37:27.419: ERROR/AndroidRuntime(844): at java.util.Timer$TimerImpl.run(Timer.java:284) 
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,在传入之前和传入后均未作判断


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


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


 

解决办法:

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


01.if (programid != null) { 
if (programid != null) {

01.…… 
 ……
}

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

延伸阅读:

Tag标签: query方法   参数args   null值  
  • 专题推荐

About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规