I am recieving data from a database server and put them in related TextView. But sometimes my app crashes! And the error is a java.lang.NullPointerException. The funny thing is right this.. The exception doesn't arise ALWAYS but quite rarely. So I think it might be related to falls in the internet connection, but I am not completely sure. Any advice?
public class fetchContactDataAsyncTask extends AsyncTask<Void, Void, Contact> {
    Contact contact;
    GetContactCallback contactCallBack;
    public fetchContactDataAsyncTask(Contact contact, GetContactCallback callBack) {
        this.contact = contact;
        this.contactCallBack = callBack;
    }
    @Override
    protected Contact doInBackground(Void... params) {
        ArrayList<NameValuePair> dataToSend = new ArrayList<>();
        dataToSend.add(new BasicNameValuePair("username", contact.username));
        dataToSend.add(new BasicNameValuePair("password", contact.password));
        dataToSend.add(new BasicNameValuePair("name", contact.name));
        dataToSend.add(new BasicNameValuePair("surname", contact.surname));
        HttpParams httpRequestParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpRequestParams, CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpRequestParams, CONNECTION_TIMEOUT);
        HttpClient client = new DefaultHttpClient(httpRequestParams);
        HttpPost post = new HttpPost(SERVER_ADDRESS + "FetchUserData.php");
        Contact returnedContact = null;
        try{
            post.setEntity(new UrlEncodedFormEntity(dataToSend));
            HttpResponse httpResponse = client.execute(post);
            HttpEntity entity = httpResponse.getEntity();
            String result = EntityUtils.toString(entity);
            JSONObject jObject = new JSONObject(result);;
            if (jObject.length() == 0){
                returnedContact = null;
            }else {
                String phone = jObject.getString("phone");
                String email = jObject.getString("email");
                String address = jObject.getString("address");
                String notes = jObject.getString("notes");
                    returnedContact = new Contact(contact.username, contact.password, contact.name, contact.surname, phone, email, address, notes);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return returnedContact;
    }
    @Override
    protected void onPostExecute(Contact returnedContact) {
        progressDialog.dismiss();
        contactCallBack.done(returnedContact);
        super.onPostExecute(returnedContact);
    }
}
And that's my log with the error
    12-02 18:41:04.849  14145-14145/ci.giacomo.net.mycontactpro4 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: cirillo.giacomo.net.mycontactpro4, PID: 14145
java.lang.NullPointerException: Attempt to read from field 'java.lang.String cirillo.giacomo.net.mycontactpro4.Contact.name' on a null object reference
        at cirillo.giacomo.net.mycontactpro4.ContactDetTextView$1.done(ContactDetTextView.java:115)
        at cirillo.giacomo.net.mycontactpro4.ServerRequests$fetchContactDataAsyncTask.onPostExecute(ServerRequests.java:372)
        at cirillo.giacomo.net.mycontactpro4.ServerRequests$fetchContactDataAsyncTask.onPostExecute(ServerRequests.java:312)
        at android.os.AsyncTask.finish(AsyncTask.java:636)
        at android.os.AsyncTask.access$500(AsyncTask.java:177)
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5910)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
 
    