安卓 java。lang.IllegalStateException游标
我想从手机中检索我使用光标的联系人列表
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_fragment_import_contact, container, false);
ContentResolver resolver = getActivity().getContentResolver() ;
Cursor cursor = resolver.query(ContactsContract.Contacts.CONTENT_URI,null,null,null,null);
while (cursor.moveToNext()){
String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
Log.i("My Info",id + "=" + name);
Cursor phoneCursor = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",new String []{id},null);
while (phoneCursor.moveToNext()){
String phone = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Log.i("My Info",phone);
}
}
我有个错误 AndroidRuntime:致命异常:主
Process: com.example.amgsoft_pc.bestprojetgla, PID: 13389
java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.
Make sure the Cursor is initialized correctly before accessing data from it.
at 安卓.database.CursorWindow.nativeGetString(Native Method)
共 (0) 个答案