0

I am developing an AppEngine application where I gotta work with Google Calendar API. Because of some reasons, we are not using the lastest version of this API (v3) and we are working with gdata-calendar-v2 which is still working until the next November.

All right, I have two methods where I am using the Calendar Service. For one hand, I am adding a new event on my calendar and I do something like:

CalendarService myService =  new CalendarService("my_calendar"); // error on this line   
myService.setUserCredentials(EMAIL, PASSWORD);

As I know, it is working fine and I am adding new events on my calendar with no problems.

For another hand, I have another method where I do something different but I am using the same snippet code to connect to Google Calendar. In this case, I get this error:

Caused by: java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.copyOf([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
  at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableTypes(AltFormat.java:399)
  at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableXmlTypes(AltFormat.java:387)
  at com.google.gdata.wireformats.AltFormat.<clinit>(AltFormat.java:49)
  at com.google.gdata.client.Service.<clinit>(Service.java:558)

The libraries that I am using with -collections- and you can be interested are:

  • Guava 11 (I already update to 18 and it's the same problem).

I know there is a very similar thread with the same problem right here but there is one difference: it is working fine in one method of my project and it is not working fine in another.

Can you give me a helping hand?

Thank you in advance, Diego.

Solution:

I have been searching in Google and I found out this thread I have changed my Guava to guava-10.0.1.jar and I don't get this error anymore.

The latest version of the gdata client library for java (version 1.46.0 as of this writing, found here: https://code.google.com/p/gdata-java-client/downloads/list) still embeds google-collections-1.0-rc1.jar inside their dependencies, and at this point it's not able to be replaced by the latest guava version.

Community
  • 1
  • 1
Diego Jovanovič
  • 234
  • 3
  • 14

1 Answers1

3

Most likely you're using two different version of Guava. Add the line

System.out.println(ImmutableSet.class.getClass().getResource("/"));

to the line before the exception to find out where the conflicting version resides.


Current Guava has the method

public static <E> ImmutableSet<E> copyOf(E[] elements) {}

Some older version (e.g., Google collections) do not. It looks like

com.google.gdata.wireformats.AltFormat$Builder

accesses the old version.

maaartinus
  • 44,714
  • 32
  • 161
  • 320
  • Hello @maaartinus, I have tried your snippet code and I get "null" when I try in both methods. By the way, I have imported ImmutableSet to print the conflict as import com.google.common.collect.ImmutableSet; Is it right? – Diego Jovanovič Sep 11 '14 at 10:06
  • @DiegoJovanovič That's strange, but possible. Then try to look for `guava-*.jar` manually. The import is right (AFAIK there's no other such thing). Maybe also print you classpath. – maaartinus Sep 11 '14 at 10:13
  • How can I print my classpath? @maaartinus – Diego Jovanovič Sep 11 '14 at 11:06
  • My classpath is right and I'm using guava-18. :( @maaartinus – Diego Jovanovič Sep 11 '14 at 11:14
  • @DiegoJovanovič There must be some old version (it may be called Google collections). Try to remove guava-18 from the classpath and look what happens. I guess, the other version will be found. There may be also multiple classloader there or whatever (but the usual solution is to find and remove the wrong JAR). – maaartinus Sep 11 '14 at 11:29
  • You know, I have tried before without guava in my project and it is not working. I have nothing with Google-collections (too old) in my project. Puf.... @maaartinus – Diego Jovanovič Sep 11 '14 at 11:38
  • @DiegoJovanovič Does `ImmutableSet.copyOf(new Object[]{"a"})` compile? Does it throw? – maaartinus Sep 11 '14 at 11:47
  • Error: The method copyOf(Iterable extends E>) in the type ImmutableSet is not applicable for the arguments (Object[]) @maaartinus – Diego Jovanovič Sep 12 '14 at 07:16
  • @DiegoJovanovič So it's a compile-time message saying that you're using the wrong version, since the right one [has the method](http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/ImmutableSet.html#copyOf(E[])). – maaartinus Sep 12 '14 at 07:59