I am trying to connect to a database on a remote server.
I have the following code with private details masked:
public static void connectToServer () {
Log.e(tag,"Inside connectToServer");
String result = "";
ArrayList toDB = new ArrayList();
//Assign namevalue pairs to toDB
try {
toDB.add(new BasicNameValuePair("A",dta.getA()));
toDB.add(new BasicNameValuePair("B",dta.getB()));
toDB.add(new BasicNameValuePair("C",dta.getC()));
toDB.add(new BasicNameValuePair("D",dta.getD()));
toDB.add(new BasicNameValuePair("E",dta.getE()));
toDB.add(new BasicNameValuePair("F",dta.getF()));
} catch (Exception e) {
Log.e(tag,e.toString());
}
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://mydom.com/myFolder/file.php");
httppost.setEntity(new UrlEncodedFormEntity(toDB));
}catch(Exception e){
Log.e(tag, "Error in http connection "+e.toString());
}
}
My manifest file is as follows:
< uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
< uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
< uses-permission android:name="android.permission.INTERNET" />
In logcat I have the following :
Inside connectToServer
java.lang.NullPointerException
Why am I getting a NullPointerException ?
Thank you.
tag
ordta
and where are they defined? – jondavidjohn Aug 2 '11 at 19:10NullPointerException
? Also, where do you initializedta
andtag
? – thegrinner Aug 2 '11 at 19:20