Skip to content Skip to sidebar Skip to footer

Null Pointer Exception While Uploading Contacts To Server

Here i am fetching the name,email,phone number from the mobile and trying to upload to server..Here if the contacts contains name,email and phone number the values will be inserted

Solution 1:

Here

if(addressBookContact.email.toString()!=null)

you try to get String from 'email' variable that is null. Correct comparing is:

if(addressBookContact.email!=null)

Solution 2:

Add two conditions as below your string might not be null but can be empty ""

if(addressBookContact.email.toString()!=null&&!addressBookContact.email.toString().equalsIgnoreCase(""))contact.put(kemail,addressBookContact.email.toString());

Solution 3:

Use TextUtils.

if(!TextUtils.isEmpty(addressBookContact.email.toString())){
    contact.put(kemail, addressBookContact.email.toString()); 
}

And if kemail is compulsory field then in else condition just pass "" empty value.

Post a Comment for "Null Pointer Exception While Uploading Contacts To Server"