异常:类型不匹配

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)

 public List<BlackNumberInfo> find(int index)
{
// 先要拿到数据库对象
SQLiteDatabase db = blackNumberOpenHelper.getWritableDatabase();
// db.rawQuery()中第一个参数就是sql语句,第二个参数是?对应的值
Cursor cursor = db.rawQuery("select * from blacknumber order by _id desc limit ?,20;", new String[]{index+""});
// 为了一次性拿到所有查到的字段,创建一个集合封装
List<BlackNumberInfo> blackNumberList = new ArrayList<BlackNumberInfo>();
while (cursor.moveToNext())
{
// 将查询的两个字段封装到一个java bean中
BlackNumberInfo blackNumberInfo = new BlackNumberInfo();
blackNumberInfo.phone = cursor.getString(0);
blackNumberInfo.mode = cursor.getString(1);
// 每次循环都将这个Javabean封装到集合中
blackNumberList.add(blackNumberInfo);
}
cursor.close();
db.close();
return blackNumberList;
}

代码第六行

select * from blacknumber
代表查询所有的字段

NumberFormatException: Invalid int类型不匹配异常——使用SQL数据库查询语句select * from blacknumber order by _id desc limit ?,20;出现-LMLPHP

数据库中的字段有_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+""});
即可

04-03 04:59