读取系统通讯录信息的时候出错:.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow
来源:互联网 发布:olafur arnalds 知乎 编辑:程序博客网 时间:2024/05/16 08:58
.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
出错代码:
if (resultCode == Activity.RESULT_OK) {
if (requestCode == REQUET_CODE) {
ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.query(data.getData(), new String[]{ContactsContract.Contacts.DISPLAY_NAME}, null, null, null);
while (cursor.moveToNext()) {
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
sb.append(name + ",");
int ifPhone = cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (ifPhone > 0) {
int id = cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts._ID));
Cursor phone = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + id, null, null);
while (phone.moveToNext()) {
String number = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
sb.append(number + ",");
}
}
text.setText(sb.toString());
}
}
=====================================================================
以上代码cursor,红色部分返回的是new String[]{ContactsContract.Contacts.DISPLAY_NAME},这里应该返回全部,即null
改正为Cursor cursor = resolver.query(data.getData(), null, null, null, null);能查看手机号码,不出错
来自为知笔记(Wiz)
0 0
- 读取系统通讯录信息的时候出错:.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow
- IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.
- Android SQLite 数据库 java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow异常
- java.lang.IllegalStateException: Couldn't read row 0, col 1 from CursorWindow.异常
- java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow异常
- Android示例java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.
- va.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor
- 已解决—java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.
- Android中操作Sqlite遇到的错误:java.lang.IllegalStateException: Couldn't read row 1, col 0 from CursorWindow
- java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow
- java.lang.IllegalStateException: Couldn't read row 0, col 6 from CursorWindow异常
- java.lang.IllegalStateException: Couldn't read row 2, col 4 from CursorWindow.
- 数据库Log之Couldn't read row 0, col -1 from CursorWindow
- Couldn't read row 0, col -1 from CursorWindow, Cursor initialization error
- ExpandableListView异常Couldn't read row 0, col -1 from CursorWindow
- 读取本地数据库,和Couldn't read row 1, col -1 from CursorWindow. Make sure the Cursor报错
- Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before
- Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before
- ContentValues的使用
- Cursor 数据库查询游标的应用
- TabLayout与ViewPager和Fragment、FragmentPagerAdapter的合用
- 使Android studio使用sdk下的docs的api文档:设置方法
- 自定义一个自己的ContentProvider程序
- 读取系统通讯录信息的时候出错:.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow
- Ogre学习笔记1(你的第一个场景)
- matlab-code folding功能 将某些行的代码折叠起来方便查看
- MyEclipse使用依赖项目在发布项目时报ClassNotFound
- 购买计划
- 104.Reverse Words in a String
- HashMap的实现原理
- 收集的48个Shell脚本小技巧
- iOS中 本地通知/本地通知详解 韩俊强的博客