开发者

AndroidHttpClient cannot be resolved to a type

I'm very new to Android development (just started today), and also very new to Java development, although I've been programming C# 开发者_运维问答for several years.

I'm trying to make an HTTP request using the AndroidHttpClient, but my code won't even compile.

Eclipse simply highlights the line of code and says, AndroidHttpClient cannot be resolved to a type.

Here's the code I'm using:

package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.net.*;
import android.net.http.*;

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;

public class HelloAndroid extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        AndroidHttpClient client = new AndroidHttpClient();
    }
}

I started with an empty Android project after installing the Android SDK and the ADT. What am I missing?


Which API target do you have within your project? AndroidHttpClient is only for API Level 8 <.

If you want to target lower versions of Android you could look at HttpClient and check if that tool meets your requirements.


I don't want to sound like a smart-ass, but your answer is in the second sentence of the documentation :) :

Don't create this directly, use the newInstance(String) factory method. 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜