2014-02-09 49 views
-1

我需要從一個url中獲取所有標題。這樣做我使用下面的代碼android - 從URL中獲取標題導致我的應用程序崩潰

try { 

    HttpClient client = HttpClientBuilder.create().build(); 
    HttpGet request = new HttpGet("http://onlineservice.banglalinkgsm.com/Construction.htm"); 
    HttpResponse response = client.execute(request); 

    Header[] headers = response.getAllHeaders(); 
    for (Header header : headers) { 

     Result =Result +"Key : " + header.getName() 
      + " ,Value : " + header.getValue(); 

} 
catch (Exception e) { } 

但當我運行該應用程序它崩潰。我無法弄清楚我犯了什麼錯誤。請幫幫我。 目前我正在添加httpclient-4.3庫。我也測試過httpclient-4.3.2庫。

,這裏是我的logcat

02-09 14:27:10.527: E/dalvikvm(7780): Could not find class 'org.apache.http.impl.conn.PoolingHttpClientConnectionManager', referenced from method org.apache.http.impl.client.HttpClientBuilder.build 
02-09 14:27:10.554: E/AndroidRuntime(7780): FATAL EXCEPTION: main 
02-09 14:27:10.554: E/AndroidRuntime(7780): java.lang.NoClassDefFoundError:  org.apache.http.impl.conn.PoolingHttpClientConnectionManager 
02-09 14:27:10.554: E/AndroidRuntime(7780):  at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:460) 
02-09 14:27:10.554: E/AndroidRuntime(7780):  at com.example.headerread.MainActivity$1.onClick(MainActivity.java:93) 
02-09 14:27:10.554: E/AndroidRuntime(7780):  at android.view.View.performClick(View.java:4212) 
02-09 14:27:10.554: E/AndroidRuntime(7780):  at android.view.View$PerformClick.run(View.java:17476) 
02-09 14:27:10.554: E/AndroidRuntime(7780):  at android.os.Handler.handleCallback(Handler.java:800) 
02-09 14:27:10.554: E/AndroidRuntime(7780):  at android.os.Handler.dispatchMessage(Handler.java:100) 
02-09 14:27:10.554: E/AndroidRuntime(7780):  at android.os.Looper.loop(Looper.java:194) 
02-09 14:27:10.554: E/AndroidRuntime(7780):  at android.app.ActivityThread.main(ActivityThread.java:5371) 
02-09 14:27:10.554: E/AndroidRuntime(7780):  at java.lang.reflect.Method.invokeNative(Native Method) 
02-09 14:27:10.554: E/AndroidRuntime(7780):  at java.lang.reflect.Method.invoke(Method.java:525) 
02-09 14:27:10.554: E/AndroidRuntime(7780):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 
02-09 14:27:10.554: E/AndroidRuntime(7780):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 
02-09 14:27:10.554: E/AndroidRuntime(7780):  at dalvik.system.NativeStart.main(Native Method) 
02-09 14:27:10.602: E/AppErrorDialog(504): Failed to get ILowStorageHandle instance 
+0

post ur logcat .. –

+0

刪除try/catch並檢查錯誤日誌 – fiddler

+0

@fiddler中的堆棧跟蹤。如果不知道錯誤,你怎麼能這樣說呢? –

回答

0

貌似沒有用soapResult聲明您soapResult變量和混亂Result

嘗試更換:

for (Header header : headers) { 

    Result =soapResult +"Key : " + header.getName() 
     + " ,Value : " + header.getValue(); 

通過

String soapResult; 
    for (Header header : headers) { 

     soapResult =soapResult +"Key : " + header.getName() 
     + " ,Value : " + header.getValue(); 
+0

對不起,這是我的編輯問題。我認爲我的問題是在HttpClient client = HttpClientBuilder.create()。build(); @fiddler –

0

檢查庫文件下訂單和出口標籤...去通過右擊項目屬性 - >然後Java Build Path ...按照上面的圖片...

+0

我已經添加httpclient-4.3-beta2庫@Anil Bhatiya –

+0

好友我不是在談論你是否添加了jar文件或者不是...我談論你有沒有在Order和Export選項卡下檢查這些jar文件根據圖像?????? –

+0

是的,我已檢查該罐子 –