0

When I am calling corresponding method, I see the following error:

Exception in thread "main" java.lang.NoSuchMethodError: com/google/common/collect/Sets.newIdentityHashSet()Ljava/util/Set;

This is my code:

Client client = ClientBuilder.newClient();
WebTarget sendWT = client.target(blueMailUrl);
url.openConnection();           
Invocation.Builder builder = ((WebTarget) sendWT)                  
     .request(MediaType.APPLICATION_JSON)
     .header("Authorization","Basic " + DatatypeConverter.printBase64Binary((byte[]) (blueMailUserid + ":" + blueMailPassword)
     .getBytes("UTF-8")));
hlg
  • 1,321
  • 13
  • 29
  • 1
    This may be helpful: https://reflectoring.io/nosuchmethod/ – hlg Jul 02 '19 at 05:47
  • The method is there in Guava 19.0 (Refer: https://guava.dev/releases/19.0/api/docs/com/google/common/collect/Sets.html). I would suggest looking at the jar files you have on classpath, this type of error often occurs due to earlier versions of jar files being on classpath with the required version and the earlier version shadows the required jar. Check once. – Ironluca Jul 02 '19 at 06:16
  • yes ,i checked in my class path jar is there.and this has only one version .I am using "google-collect-0.5.jar".It has only one version . – Hemalata Mohanta Jul 02 '19 at 07:08
  • Even I am trying with the jar "jersey-guava-2.23.1" ,for this also same error .Anyone have experienced on this .Please suggest me how to resolved it. – Hemalata Mohanta Jul 02 '19 at 07:35

1 Answers1

0

java.lang.NoSuchMethodError occurs when a method (actually the class) is available during compilation and the same is missing during runtime.

Make sure all the dependencies of the project is added to the classpath during runtime

In your case, check google-collections jar file is available in the classpath

Adhi
  • 149
  • 2
  • 11
  • java.lang.NoSuchMethodError occurs when a method (actually the class) is available during compilation and the same is missing during runtime. ::: How we can avoid this one ,please tell us.Thank you – Hemalata Mohanta Jul 02 '19 at 06:30
  • @HemalataMohanta It has been answered here, look at the solution provided here https://stackoverflow.com/questions/36249002/java-lang-nosuchmethoderror-com-google-common-collect-sets-newconcurrenthashset – Adhi Jul 02 '19 at 09:52