Glenda Karen wrote:I tried adding the dependency but sill got the error:(
I checked the external library and I can see the class is there.
Oh .. I guess the build system is added the dependency for you.
I created a simple (non Android) project using your code fragment with a single dependency on org.apache.httpcomponents:fluent-hc:4.5.10 and let Maven bring-in whatever else might be required. It ran successfully without any exceptions.
Maybe check to make sure that a different version of httpclient isn't being pulled-in by the framework or as a dependency for some other jar.
I am not actively working with Android so my advice may not be the best.
After reading this note from Apache, I understand that the Android framework contains a fork of the Apache code (httpclient, httpcore, etc.), and that it has not been kept current. It seems like your code is picking up the Apache classes from the framework/SDK, and not the ones that you are specifying. According to the note, the forked code was removed in API 26, so if you have the option to move to a more recent version of the SDK, that may solve your problem.
Alternatively, you could use a different HTTP client/UA sock as OkHttp (I have used this before). I don't think you would be able to use the latest version with API 19, but com.squareup.okhttp3:okhttp:3.14.9 would probably work (you would need to experiment a bit).
The equivalent to what you were doing with Apache would be something like this:
Glenda Karen wrote:At the moment the API needs to stay at 19 to be compatible with the devices the app is running on.
I had the same constraint with the last Android project I worked on. We were using ruggedized industrial handsets which were running KitKat 4.4 (API 19). It actually ended-up being a benefit for what we were doing (location tracking, PTT voice) since the earlier versions of Android were less restrictive on what system services could be accessed (many have been taken-away for security-related reasons), and were more permissive on allowing tasks to run unencumbered in the background (more restrictive now in an attempt to improve battery lifetime).