This part of my code checks to see that when the user clicks on a contact, the contact actually has a phone number, otherwise a message is displayed and nothing else is done.
I am confused as to where my null pointer exception is coming from....
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
if (c.moveToFirst())
{
String stringName = c.getString(c.getColumnIndexOrThrow(People.NAME));
if(c.getColumnIndex(People.NUMBER)!= -1 )
{
stringNumber = c.getString(c.getColumnIndexOrThrow(People.NUMBER));
}
if((!stringNumber.equals(null)) && (stringNumber.length() >= 12))
{
name.setText(stringName);
number.setText(stringNumber);
}
else
{
Context context = getApplicationContext();
CharSequence text = "That contact has an invalid phone number.";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
my error is "failure delivering result RESULTINFO" , and it also says it's a nullpointer exception error in this line:
if((!stringNumber.equals(null)) && (stringNumber.length() >= 12))
earlier in the code, I declare stringNumber to initialize to null. I thought that since the first part of the if evals to false, it wouldn't even check the second part (which is where I think the error is coming from).