我正在尝试使用cardview显示与recyclerview的联系,并且出现此错误:
java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView $ LayoutManager)'
Fragment Parent是BottomNavigationViewTab-我试图显示联系人的地方。
Contact_List_Fragment.java
public class Contact_List_Fragment extends android.support.v4.app.Fragment {
RecyclerView recyclerView;
ArrayList<String> contact_names = new ArrayList<>(), mobile_numbers = new ArrayList<>();
public Contact_List_Fragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View contact_fragment = inflater.inflate(R.layout.contact_list_fragment, container, false);
String[] PROJECTION_MAIN = new String[]{
ContactsContract.Contacts._ID,
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.Contacts.DISPLAY_NAME
};
Cursor cursor = getActivity().getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
PROJECTION_MAIN, null, null, null);
while (cursor.moveToNext()) {
String …Run Code Online (Sandbox Code Playgroud)