gpt4 book ai didi

java - android中如何解决异常

转载 作者:行者123 更新时间:2023-12-01 15:50:46 25 4
gpt4 key购买 nike

我在android中编写了HttpDelete来调用REST Web服务。

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;
}

我得到的异常(exception)是

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

有人知道为什么吗?

最佳答案

您是否检查了 list 文件的 Internet 权限?

关于java - android中如何解决异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6094676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com