java.lang.IllegalStateException CURSOR

时间:2017-04-08 20:05:06

标签: java android

我想从手机中检索我的联系人列表,因为我使用了光标

 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:FATAL EXCEPTION:main

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 android.database.CursorWindow.nativeGetString(Native Method)

0 个答案:

没有答案