![](/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.