Good, I have the following problem or doubt is when executing the following method in my activity main
public String ObtenerDatos(String persona) {
HashMap<String,String> numero = new HashMap<String,String>();
String[] projeccion = new String[]{ContactsContract.Data.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER};
String selectionClause = ContactsContract.Data.MIMETYPE + "='" +
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND "
+ ContactsContract.CommonDataKinds.Phone.NUMBER + " IS NOT NULL";
String sortOrder = ContactsContract.Data.DISPLAY_NAME + " ASC";
Cursor c = getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
projeccion,
selectionClause,
null,
sortOrder);
numero.clear();
while (c.moveToNext()) {
numero.put(c.getString(0).toLowerCase() , c.getString(1));
}
c.close();
Iterator it = numero.keySet().iterator();
String select = null;
select = numero.get(persona);
if (select == null || select == ""){
select = "123";
}
return select;}
this works without problems, but when calling the same method from another class
Contactos contact = new Contactos();
contact.ObtenerDatos("casa");
I generate a NullPointerException,
for which I do not know how to solve this problem I appreciate your reading and possible clarifications.
I add:
this error occurs when in class Contactos
in method ObtenerDatos
when% is called cursor c