我需要從一個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
post ur logcat .. –
刪除try/catch並檢查錯誤日誌 – fiddler
@fiddler中的堆棧跟蹤。如果不知道錯誤,你怎麼能這樣說呢? –