Ryan
Ryan

Reputation: 2998

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?

Upvotes: 1

Views: 7153

Answers (2)

Ian
Ian

Reputation: 3520

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. 

Upvotes: -2

Wroclai
Wroclai

Reputation: 26925

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.

Upvotes: 3

Related Questions