Reputation: 1525
i have written HttpDelete in android to call REST web service.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView txt = (TextView) findViewById(R.id.textView1);
txt.setText(getInputStreamFromUrl("http://192.168.37.241:8080/kyaw/k"));
}
public static String getInputStreamFromUrl(String url) {
InputStream content = null;
HttpResponse response = null;
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpDelete delete=new HttpDelete(url);
put.setHeader("Content-Type","application/vnd.org.snia.cdmi.container");
response = httpclient.execute(delete);
content = response.getEntity().getContent();
}catch (Exception e) {
Log.e("[DELETE REQUEST]", "Network exception");
}
String result=response.getStatusLine().toString()+"\n"+response.getHeaders(url);
return result;
}
And I get the exception which is
05-23 08:30:16.868: ERROR/[DELETE REQUEST](1197): Network exception
05-23 08:30:16.868: DEBUG/AndroidRuntime(1197): Shutting down VM
05-23 08:30:16.878: WARN/dalvikvm(1197): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-23 08:30:16.908: ERROR/AndroidRuntime(1197): FATAL EXCEPTION: main
05-23 08:30:16.908: ERROR/AndroidRuntime(1197): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.putandroid}: java.lang.NullPointerException
Do anyone know why?
Upvotes: 0
Views: 450
Reputation: 40168
In the onCreate() function on line 4 we find that after initializing your TextView
you are trying to set a value.
You must use a Handler
object because you cannot update an UI objects while in a separate thread.
Here is some link for your help
https://web.archive.org/web/20130306131310/http://thedevelopersinfo.com/?p=150
Upvotes: 0
Reputation: 114767
No idea for the network exception (yet) but the last NPE is most likely because the previous exception is thrown before response
has been initialized through httpclient.execute(delete)
.
You should rewrite your catch
block and write the name of the catched exception and the message to the log.
Upvotes: 0