程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> service-如何解決 android 中的異常問題?

service-如何解決 android 中的異常問題?

編輯:編程綜合問答
如何解決 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

誰能幫忙解釋一下呢?

最佳回答:


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 "";
        }
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved