0

I am trying to implement google analytics with java api.but i am stuck with this exception

java.lang.NoSuchMethodError: com.google.common.base.Joiner.on(C)Lcom/google/common/base/Joiner;
at com.google.api.client.auth.oauth2.AuthorizationCodeFlow$Builder.setScopes(AuthorizationCodeFlow.java:644)
at com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow$Builder.setScopes(GoogleAuthorizationCodeFlow.java:256)
at com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow$Builder.<init>(GoogleAuthorizationCodeFlow.java:225)
at com.stpl.pats.bl.event.general.HelloAnalyticsApiSample.authorize(HelloAnalyticsApiSample.java:71)
at com.stpl.pats.bl.event.general.HelloAnalyticsApiSample.initializeAnalytics(HelloAnalyticsApiSample.java:157)
at com.stpl.pats.bl.event.general.HelloAnalyticsApiSample.main(HelloAnalyticsApiSample.java:39)

please suggest me what wrong with my code...

arjun3037
  • 17
  • 3

2 Answers2

1

Apparently the version found at runtime does not have a Joiner.on(char separator) returning a Joiner, even though the version in Guava has always had it since its import from google-collections, so it looks like an embedded version of the code in another jar (so nothing is wrong in your code, only in your dependencies).

I assume HelloAnalyticsApiSample is your code and can be modified. Add the following in your main() before line 39:

System.out.println(com.google.common.base.Joiner.class
        .getProtectionDomain().getCodeSource().getLocation());

(or using your logging framework of choice). You should then be getting the path of the jar containing the offending version.

Frank Pavageau
  • 11,477
  • 1
  • 43
  • 53
0

In my case, it was because I also had a google-collection-rc1.jar in my project, and so an older version of the Joiner class (without the method) was being found, and not the correct version that is inside the guava jar.

Either remove that collections jar (recommended) or move it to later in your class path than the guava jar (which is basically the same thing, as I think all the classes in the collection jar are in the guava jar).

Andrew Mackenzie
  • 5,477
  • 5
  • 48
  • 70