标签:hone cti format activity 修改 code ret ima inf
异常:类型不匹配
05-06 08:12:38.151: E/AndroidRuntime(14904): java.lang.NumberFormatException: Invalid int: "18600000099"
05-06 08:12:38.151: E/AndroidRuntime(14904): at com.itheima.mobilesafe74.activity.BlackNumberActivity$Myadapter.getView(BlackNumberActivity.java:122)
1 public List<BlackNumberInfo> find(int index) 2 { 3 // 先要拿到数据库对象 4 SQLiteDatabase db = blackNumberOpenHelper.getWritableDatabase(); 5 // db.rawQuery()中第一个参数就是sql语句,第二个参数是?对应的值 6 Cursor cursor = db.rawQuery("select * from blacknumber order by _id desc limit ?,20;", new String[]{index+""}); 7 // 为了一次性拿到所有查到的字段,创建一个集合封装 8 List<BlackNumberInfo> blackNumberList = new ArrayList<BlackNumberInfo>(); 9 while (cursor.moveToNext()) 10 { 11 // 将查询的两个字段封装到一个java bean中 12 BlackNumberInfo blackNumberInfo = new BlackNumberInfo(); 13 blackNumberInfo.phone = cursor.getString(0); 14 blackNumberInfo.mode = cursor.getString(1); 15 // 每次循环都将这个Javabean封装到集合中 16 blackNumberList.add(blackNumberInfo); 17 } 18 cursor.close(); 19 db.close(); 20 return blackNumberList; 21 }
代码第六行
select * from blacknumber
代表查询所有的字段
而
数据库中的字段有_id,phone,mode三个
所以当调用代码13,14行
blackNumberInfo.phone = cursor.getString(0);
blackNumberInfo.mode = cursor.getString(1);
0对应的其实是_id而不是phone
1对应的其实是phone而不是mode
所以出现问题
修改SQL查询语句解决这个问题:
第六行改为
Cursor cursor = db.rawQuery("select phone,mode from blacknumber order by _id desc limit ?,20;", new String[]{index+""});
即可
标签:hone cti format activity 修改 code ret ima inf
原文地址:http://www.cnblogs.com/yfqmarkblogs/p/6817188.html