![](/img/trans.png)
[英]Exception in thread "main" java.lang.RuntimeException: Stub XmlPullParserFactory
[英]Exception in thread “main” java.lang.RuntimeException: Stub
嘿大家我得到這個奇怪的錯誤,我無法弄清楚為什么?
package com.androidbook.services.httpget;
import java.io.BufferedReader; import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.os.Bundle;
public class HttpGetDemo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
BufferedReader in = null;
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://code.google.com/android/");
HttpResponse response = client.execute(request);
in = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String page = sb.toString();
System.out.println(page);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(); } finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
而錯誤就是這個
Exception in thread "main" java.lang.RuntimeException: Stub!
at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:5)
at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:7)
at ClientWithResponseHandler.main(ClientWithResponseHandler.java:15)`
你在這里有android SDK導入。 您是否有機會嘗試從您的電腦上運行它(例如,從標准的Java項目)?
此錯誤意味着您無權訪問您嘗試使用的實際方法或對象,但只能訪問存根 - 一種方法,它只會拋出您看到的此異常。
確保你在模擬器(或在Android設備上)上運行你的android項目,並且你沒有從android中導入任何不在Android設備上運行的項目。
你得到的是因為Android包中的apache類與JVM中的apache類不同。 向常規apache類添加依賴項,如果使用maven,請確保在測試平台的android平台之前加載這些依賴項(有點與jUnit 4相同)。 之后,您將能夠在JVM中測試包含apache HTTP方法的類,但考慮到JVM不會對服務器進行任何調用,因此這僅用於測試您的所有其他部分。類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.