Exception in thread “main” Java lang.RuntimeException:Stub

Hey, guys, I got this strange mistake. I can't figure out why?

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();
                }
            }
        }
    }
}

And that's the mistake

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)`

Solution

You have Android SDK import here Have you had the opportunity to try running it from your computer (for example, from a standard Java project)?

This error means that you do not have access to the actual method or object you are trying to use, but only to the stub - a method that will only throw the exception you see

Make sure you run your Android project on the emulator (or on an Android device) and you don't import any projects from Android that don't run on an Android device

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>