您的位置:首页 > 移动开发 > Android开发

android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x580608

2015-03-02 10:08 609 查看
***************************************

在经过几年的经验累积之后,我终于决定整理一下曾经遇到的各种问题,给各位走在android开发路上的朋友一点帮助,更多相关问题,请访问我的博客:http://blog.csdn.net/xiaoliluote 如果您对该问题有更多的解决方式,请留言,验证之后我会编辑博客

***************************************

新年回来写代码,居然出了这个错(android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x580608),心想难道过了个年,人变傻了?仔细检查没发现代码有什么问题啊,代码如下:

String select=null;

String[] selection =new String[filter.size()];

int code=0;

Iterator iter =filter.entrySet().iterator();

while(iter.hasNext()){

Entry entry =(Entry)iter.next();

String key=entry.getKey().toString();

String value =entry.getValue().toString();

if(select ==null)

select = key+" like '%?%' ";

else

select = select +" and "+key+" like '%?%' ";

selection[code] = value;

code++;

}

Cursor cursor = db.query(mHeaderTableName, new String[] { "*" }, select,

selection, null, null, null);

但是查询就是会报错,后来终于恍然大悟, 模糊查询的 %%,在这里不能写在 参数select 里面,要写在参数selection 里面,改过之后代码如下,红色的地方是改动的代码:
String select=null;

String[] selection =new String[filter.size()];

int code=0;

Iterator iter =filter.entrySet().iterator();

while(iter.hasNext()){

Entry entry =(Entry)iter.next();

String key=entry.getKey().toString();

String value =entry.getValue().toString();

if(select ==null)

select = key+" like ? ";

else

select = select +" and "+key+" like ? ";

selection[code] = "%"+value+"%";

code++;

}

Cursor cursor = db.query(mHeaderTableName, new String[] { "*" }, select,

selection, null, null, null);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐