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);
在经过几年的经验累积之后,我终于决定整理一下曾经遇到的各种问题,给各位走在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);
相关文章推荐
- Android 模糊搜索rawquery bind or column index out of range: handle 0x2fb180 报错
- Android 模糊搜索rawquery bind or column index out of range: handle 0x2fb180 报错
- getWritableDatabase called recursively;bind or column index out of range
- SQLiteException: bind or column index out of range
- SQLiteException: bind or column index out of range
- Android 中 java.lang.IllegalArgumentException: pointerIndex out of range 异常的处理方法
- Android 多点触控错误处理(java.lang.IllegalArgumentException: pointerIndex out of range)
- Android java.lang.IllegalArgumentException: pointerIndex out of range
- android ICS 4.0.3 报 java.lang.IllegalArgumentException: pointerIndex out of range 解决方案
- Android 中 java.lang.IllegalArgumentException: pointerIndex out of range 异常的处理方法
- SQLite: Cannot bind argument at index 1 because the index is out of range. The statement has 0 param
- Lucene.Net 的“System.IndexOutOfRangeException: 索引超出了数组界限”错误
- java.lang.IllegalArgumentException: pointerIndex out of range 问题的两种解决办法
- System.IndexOutOfRangeException: 索引超出了数组界限
- java.lang.IllegalArgumentException: pointerIndex out of range
- Android4.1上出现java.lang.IllegalArgumentException: pointerIndex out of range
- java.lang.IllegalArgumentException: pointerIndex out of range
- android.database.CursorIndexOutOfBoundsException: Index <m> requested, with a size of <n>
- list from JavaBean. Cause java.lang.StringIndexOutOfBoundsException: String index out of range: -1
- 解决java.lang.IllegalArgumentException: pointerIndex out of range的错误