Last active
February 23, 2020 09:43
-
-
Save jonikarppinen/51e6baeaa5af8d2d74a3bacefa85386b to your computer and use it in GitHub Desktop.
Fixes to "Retrieving a List of Contacts" Android tutorial by Google: https://developer.android.com/training/contacts-provider/retrieve-names.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 ?
Try SO answer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there,
I'm getting an error trying to get the ListView object.
contactsList = (ListView) getActivity().findViewById(R.id.list); ... contactsList.setAdapter(cursorAdapter);
Do I need to use
setContentView()
method ?