0

I'm having this issue where I'm getting an error that states, "cannot resolve symbol". These words below are red(Included in code below):

HttpEntity

HttpResponse

ClientProtocolException

HttpPost

DefaultHttpClient

I've already tried:

  1. Build > Clean Project

  2. Build > Rebuild Project

  3. File > Invalidate Caches/Restart > Invalidate and Restart

  4. Close Android-Studio and restart my MacBook.

  5. Sync Project with Grade Files.

None of these worked & these are the suggestions I've tried which is what I've been coming across in Google searches.

My mainActivity.java class is fine but my appMaking.java class is throwing me this error.

Thanks for reading.

appMaking.java

package com.apress.gerber.currencies;
import android.util.Log;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;

public class appMaking {

}
dbv
  • 19
  • 1
  • What is your target API ? – swbradshaw Nov 28 '16 at 21:21
  • @swbradshaw I'm not sure. Where can I find this out? – dbv Nov 28 '16 at 21:22
  • You have added the libraries for [httpcore](https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore) and [httpclient](https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient), correct? – Matt Clark Nov 28 '16 at 21:23
  • Look at build.gradle file for your app. You'll find compileSdkVersion listed near the top. – swbradshaw Nov 28 '16 at 21:25
  • @MattClark I've only written what's on my original post when it comes to `httpcore` and `httpclient` so I guess I haven't added the libraries for them. How do I do so? – dbv Nov 28 '16 at 21:26
  • @swbradshaw Oh ok, I see it. It says `compileSdkVersion 25`. – dbv Nov 28 '16 at 21:27

2 Answers2

1

Android 6 (API 23) removed the Apache HTTP Library.

You can still reference it by adding the following to your build.gradle file:

android {
   useLibrary 'org.apache.http.legacy'
}
swbradshaw
  • 824
  • 9
  • 14
  • I've added your code to my build.grade file, the red is gone from the import statements (now it's saying it's unused) but now when I declare objects, i.e. `static inputStream s = null` The `inputStream` is red. – dbv Nov 28 '16 at 21:46
  • inputStream is not a class. Try InputStream instead, make sure to include java.io.InputStream at the top of the file. – swbradshaw Nov 29 '16 at 14:38
0

This is most likely because of the fact that you do not have apache httpclient in your library path.

According to this page, you should be able to get this working by adding the following to your gradle file.

dependencies {
    compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
}

edit

According to the link provided by swbradshaw, you should try and avoid using httpcomponenets in new code, and use the libraries provided to you instead.

i.e., HttpURLConnection - see this post for more usage details.

Community
  • 1
  • 1
Matt Clark
  • 24,947
  • 16
  • 62
  • 114
  • I've added your code to my build.grade file, the red is gone from the import statements (now it's saying it's unused) but now when I declare objects, i.e. `static inputStream s = null` The `inputStream` is red. – dbv Nov 28 '16 at 21:48
  • [InputStream](https://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html), capital I. – Matt Clark Nov 28 '16 at 21:51
  • ahh nice catch :) But it's still giving me the red error :( – dbv Nov 28 '16 at 21:52