Java 在android studio中向下移动到APK 22时,使用光标将联系人放入列表视图不起作用

Java 在android studio中向下移动到APK 22时,使用光标将联系人放入列表视图不起作用,java,android,listview,android-studio,arraylist,Java,Android,Listview,Android Studio,Arraylist,我创建了这个函数,它使用光标获取存储在arraylist中的所有联系人,然后在片段中使用listview显示。当我用运行APK 23的平板电脑测试它时,它工作正常,但当我转到APK 22时,它就不工作了。这背后的原因是什么 以下是函数: // grabs the contacts and stores them into the arraylist public void GetContactsIntoArrayList() { Toast.makeText(getActivity(),

我创建了这个函数,它使用光标获取存储在arraylist中的所有联系人,然后在片段中使用listview显示。当我用运行APK 23的平板电脑测试它时,它工作正常,但当我转到APK 22时,它就不工作了。这背后的原因是什么

以下是函数:

// grabs the contacts and stores them into the arraylist
public void GetContactsIntoArrayList() {
    Toast.makeText(getActivity(), "Function was hit", Toast.LENGTH_LONG).show();
    cursor = getActivity().getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);

    while (cursor.moveToNext()){
        name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
        contacts.add(name);
        Toast.makeText(getActivity(), name + " added to the array list", Toast.LENGTH_LONG).show();
    }
}

到底是什么不起作用?它实际上并没有将联系人放入数组列表中。我知道它击中了函数,因为屏幕上显示的吐司说函数被调用了。这真的让人困惑,就像我说的,当平板电脑运行APK 23时,它就工作了。只是当我们恢复到之前的APK时,它不会。