hcg_21 2013-01-31 08:02 采纳率: 0%
浏览 2697
已采纳

如何解决 android 中的异常问题?

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

但是获得以下异常

868: ERROR/[DELETE REQUEST](1197): Network exception
01-23 08:30:16.868: DEBUG/AndroidRuntime(1197): Shutting down VM
01-23 08:30:16.878: WARN/dalvikvm(1197): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-23 08:30:16.908: ERROR/AndroidRuntime(1197): FATAL EXCEPTION: main
01-23 08:30:16.908: ERROR/AndroidRuntime(1197): java.lang.RuntimeException: Unable to start activity ComponentInfo

谁能帮忙解释一下呢?

  • 写回答

3条回答 默认 最新

  • Billy_崔海斌 2013-01-31 08:31
    关注
    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();
                String result=response.getStatusLine().toString()+"\n"+response.getHeaders(url);
                return result;
              }catch (Exception e) {
                Log.e("[DELETE REQUEST]", "Network exception");
              }
              return "";
            }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于某款2.13寸墨水屏的问题
  • ¥15 obsidian的中文层级自动编号
  • ¥15 同一个网口一个电脑连接有网,另一个电脑连接没网
  • ¥15 神经网络模型一直不能上GPU
  • ¥15 pyqt怎么把滑块和输入框相互绑定,求解决!
  • ¥20 wpf datagrid单元闪烁效果失灵
  • ¥15 券商软件上市公司信息获取问题
  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了
  • ¥15 陆空双模式无人机怎么做