java - Android: Null object reference -
i trying have list of contacts, each quickcontactbadge
. when tried add quickcontactbadge
, application crasher , logcat says null object reference on mcursor
when call getcolumnindex();
. doing wrong, , code work correctly implement quickcontactbadge
?
private cursoradapter madapter; private cursor mcursor; private string currentquery; private int midcolumn; private int mlookupkeycolumn; private uri mcontacturi; private quickcontactbadge mbadge; private static final string[] projection = { contacts._id, contacts.display_name_primary, contacts.lookup_key, contacts.photo_thumbnail_uri, contacts.has_phone_number }; private static final string[] = { contacts.display_name_primary }; private static final int[] = { r.id.contact_text }; private static final string selection = "(" + contacts.in_visible_group + " = 1) , (" + contacts.has_phone_number + " != 0 )"; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); mcursor = null; madapter = new simplecursoradapter(getactivity(), r.layout.contacts_list_item, mcursor, from, to, 0); mbadge = (quickcontactbadge) getactivity().findviewbyid(r.id.badge); midcolumn = mcursor.getcolumnindex(contacts._id); mlookupkeycolumn = mcursor.getcolumnindex(contacts.lookup_key); mcontacturi = contacts.getlookupuri( mcursor.getlong(midcolumn), mcursor.getstring(mlookupkeycolumn) ); mbadge.assigncontacturi(mcontacturi); }
mcursor = null; madapter = new simplecursoradapter(getactivity(), r.layout.contacts_list_item, mcursor, from, to, 0); mbadge = (quickcontactbadge) getactivity().findviewbyid(r.id.badge); midcolumn = mcursor.getcolumnindex(contacts._id);
check first , last line here... mcursor null, , calling getcolumnindex() on it.
Comments
Post a Comment