-
-
Save jonikarppinen/51e6baeaa5af8d2d74a3bacefa85386b to your computer and use it in GitHub Desktop.
// Fixes to compilation errors in "Define the onItemClick() method" section | |
// Doesn't compile | |
Cursor cursor = parent.getAdapter().getCursor(); | |
// Fixed (not sure if this is the cleanest way though) | |
Cursor cursor = ((SimpleCursorAdapter) parent.getAdapter()).getCursor(); | |
// Doesn't compile | |
mContactId = getLong(CONTACT_ID_INDEX); | |
// Fixed | |
mContactId = cursor.getLong(CONTACT_ID_INDEX); | |
// Doesn't compile | |
mContactKey = getString(CONTACT_KEY_INDEX); | |
// Fixed. Note that the constant defined earlier in the tutorial is LOOKUP_KEY_INDEX | |
mContactKey = cursor.getString(LOOKUP_KEY_INDEX); |
Hi there,
I'm getting an error trying to get the ListView object.
contactsList = (ListView) getActivity().findViewById(R.id.list); ... contactsList.setAdapter(cursorAdapter);
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
Do I need to use setContentView()
method ?
Hi there,
I'm getting an error trying to get the ListView object.
contactsList = (ListView) getActivity().findViewById(R.id.list); ... contactsList.setAdapter(cursorAdapter);
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
Do I need to use
setContentView()
method ?
Try SO answer
Also in
contacts_list_view.xml
:Should be:
As the fragment does not recognize this (in @mostafahadian's remark):