• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

java.lang.NoSuchFieldError

 
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am running code in an app to send data to a web service.
The app is in API 19 and I am using org.apache.httpcomponents

However I keep getting an error:
java.lang.NoSuchFieldError: org.apache.http.conn.ssl.AllowAllHostnameVerifier.INSTANCE


The code looks like:

and running the request:

The build.gradle looks like:


Thanks so much!
 
Marshal
Posts: 3501
495
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like org.apache.httpcomponents:fluent-hc:4.5.10 has a dependency on org.apache.httpcomponents:httpclient:4.5.10, and that httpclient jar contains the org.apache.http.conn.ssl.AllowAllHostnameVerifier class which is missing.




 
Glenda Karen
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you!

I tried adding the dependency but sill got the error:(

I checked the external library and I can see the class is there.
 
Ron McLeod
Marshal
Posts: 3501
495
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Glenda Karen
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much! Really appreciate your time helping me!

It seems one of the SDKs we are using in the app is calling maven.apache could that be the problem? and is there anything we can do about it?(since we need this sdk)
 
Ron McLeod
Marshal
Posts: 3501
495
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 97
2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much!

Wow that is very interesting re apache.

At the moment the API needs to stay at 19 to be compatible with the devices the app is running on.

Perhaps though as you mentioned, I can use another library. I think java.net.HttpURLConnection; is compatible with API 19, so maybe that could be a solution.

Thanks again for all your help!
 
Ron McLeod
Marshal
Posts: 3501
495
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

Good luck with your development.
 
Glenda Karen
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good to know API 19 is still being used and actually has some benefits too:)

Thanks so much again for all the help!
 
Glenda Karen
Ranch Hand
Posts: 97
2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ron McLeod,

Just wanted to thank you again for your help! We used the OkHttp library as you suggested and it worked!

(We used verison com.squareup.okhttp3:okhttp:3.12.0 for Api 19)
 
Ron McLeod
Marshal
Posts: 3501
495
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome - glad to hear to got it working
 
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic