线程"main"中的异常java.lang.RuntimeException:Stub

hel*_*ere 4 java apache android exception httpclient

嘿大家我得到这个奇怪的错误,我无法弄清楚为什么?

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();
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

而错误就是这个

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)`
Run Code Online (Sandbox Code Playgroud)

小智 8

你在这里有android SDK导入.您是否有机会尝试从您的电脑上运行它(例如,从标准的Java项目)?

此错误意味着您无权访问您尝试使用的实际方法或对象,但只能访问存根 - 一种方法,它只会抛出您看到的此异常.

确保你在模拟器(或在Android设备上)上运行你的android项目,并且你没有从android中导入任何不在Android设备上运行的项目.