#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    HTTP Helper Class - NullPointerException


    Hello All!

    I'm pretty new to Java development so please bare with me

    I'm trying to create a HTTP Helper class that will post and get data from an external database.

    Currently, I'm just executing a script on the server and not passing data to it. When I run the helper I'm getting the exception NullPointerException.

    Why would I be getting this? Thanks for any help you can give.

    I made sure the have the following in my Manifest file

    Code:
    <uses-permission android:name="android.permission.INTERNET" />
    Here's the HTTP Helper class

    Code:
    package com.viviosoft.gpsproject;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    
    import android.util.Log;
    
    public class HTTPHelper implements Runnable{
    
    	private String httpLocation;
    
    	public String setHttpLocation(String location) {
    		return httpLocation = location;
    	}
    
    	public void run() {
    		try {
    			HttpClient httpClient = new DefaultHttpClient();
    			HttpPost httpPost = new HttpPost(this.httpLocation);
    			// httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    			HttpResponse response = httpClient.execute(httpPost);
    			HttpEntity entity = response.getEntity();
    			
    			Log.d("debug", "ENDED TRY");
    		} catch (Exception e) {
    			Log.e("log_tag", e.toString());
    		}
    	}
    	
    	public void sendData() {
    		Thread t = new Thread(new HTTPHelper(), "My Thread");
    		t.start();
    	}
    
    }
    Calling the Class:

    Code:
    HTTPHelper httpHelper = new HTTPHelper();
    httpHelper.setHttpLocation("http://www.domain.com/application/services/send_cords.php");
    httpHelper.sendData();
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    NullPointerException - Update


    After debugging. I realized that the location isn't getting passed to the HttpPost() set in the setHttpLocation() method???

    Not sure why this would be happening.

    Any thoughts? Thank you!

IMN logo majestic logo threadwatch logo seochat tools logo