3

I get the following error:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.of([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)
at testproject.TestProject.run(TestProject.java:22)
at testproject.TestProject.main(TestProject.java:31)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

This comes from the following code:

package testproject;

import com.google.gdata.client.youtube.YouTubeService;
import com.google.gdata.util.*;
import java.util.logging.*;

public class TestProject {

  public static void main(String[] args) {
    try {
      YouTubeService service = new YouTubeService("Test", "developerKey");
      service.setUserCredentials("root@gmail.com", "pa$$word");
    } catch (AuthenticationException ex) {
      Logger.getLogger(TestProject.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
}

At first, I included every library in http://code.google.com/p/gdata-java-client/downloads/list and also imported much more than I needed to. I've since removed the libraries I deemed unnecessary (thanks thinksteep). So the libraries I'm currently including are the following libraries:

mail.jar
activation.jar
ant.jar
gdata-core-1.0.jar
gdata-media-1.0.jar
guava-11.0.1.jar
gdata-youtube-2.0.jar
gdata-youtube-met-2.0.jar

(There are probably a few libraries there which are not necessary... But I'm at my whit's end...) I'm just trying to test getting a YouTube service so I can get things going on this project, but no dice. Oh, and I've also included this library: http://code.google.com/p/guava-libraries because before I was getting a NoClassDefFound error and including that library seemed to solve it. Thank you in advance for the help! Oh, and I also followed every step exactly (or at least I think so) in the gdata getting started guide. My test build was successful by the end... Thanks again!

Community
  • 1
  • 1
kentcdodds
  • 27,113
  • 32
  • 108
  • 187

8 Answers8

12

Adding more than required may cause issue too. java.lang.NoSuchMethodError error typically happens in case where runtime couldn't find required method with exact signature. Possible causes are:

1) There might be mulitple jars with same code, which may cause wrong class get loaded.

2) Incompatable version of jar, the jar you have in classpath might be older version/newer version.

Make sure none of those cases happening.

kosa
  • 65,990
  • 13
  • 130
  • 167
  • Thanks for your response. I'm still getting the error. I removed all the jars I thought were unnecessary and removed all the imports which are unnecessary and received the same error. I've updated the post to reflect what the code now looks like. – kentcdodds Feb 10 '12 at 04:33
  • Check this link, it seems something contradicting with guava library. http://code.google.com/p/gdata-java-client/issues/detail?id=344 – kosa Feb 10 '12 at 04:36
  • That's my issue exactly! Now I just need to figure out what they mean with their solution... Okris (on that thread) says: _Solution is by the way to change to ImmutableSet.copyOf(E[] elements)_, but I'm not sure what that means I'm supposed to do. Could you direct me that one more step? Thanks for your help! – kentcdodds Feb 10 '12 at 04:45
  • Can you move to lower version of Guava? It seems with 11 you are having this issue. The suggested code change may be best option for you. I feel the only work around for you is, lower version of Guava and file an issue with Gdata project. – kosa Feb 10 '12 at 04:49
  • I'll give that a shot... One sec – kentcdodds Feb 10 '12 at 04:52
  • Spectacular! It worked fabulously! Thank you very much! For anyone reading: **THIS IS THE ANSWER** to my problem: Just get an earlier version of Guava. You can find that [here](http://code.google.com/p/guava-libraries/wiki/Release10). Thanks again thinksteep! – kentcdodds Feb 10 '12 at 05:00
  • @Nambari I m getting an error : The method `setOAuth2Credentials(com.google.api.client.googleapis.auth.oauth2.GoogleCredential)` is undefined for the type `com.google.gdata.client.contacts.ContactsService` . Any help ??? – Yogesh Seralia Aug 11 '15 at 13:38
4

Issue with latest version of gdata still referencing older guava methods

Check Out http://code.google.com/p/gdata-java-client/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary&groupby=&sort=&id=344

Solution

I switched to guava-r07.jar located at http://code.google.com/p/guava-libraries/downloads/detail?name=guava-r07.zip&can=4&q=

This got me past ContactsService service = new ContactsService("");

Jar's in use:

  • Default Eclipse plugin jar's
  • gdata-base-1.0.jar
  • gdata-client-1.0.jar
  • gdata-contacts-3.0.jar
  • gdata-core-1.0.jar
  • gdata-media-1.0.jar
  • guava-r07.jar

  • Apache (servlet-api.jar)

  • JavaMail (mail.jar)
  • JavaBeans Activation Framework (activation.jar)
Tim OBrien
  • 41
  • 1
  • 5
  • 1
    +1 But note that this issue has now been fixed by release 1.47.0: http://code.google.com/p/gdata-java-client/issues/detail?id=344#c13 – Paul Bellora May 11 '12 at 16:07
0

The Required library jars are as follows.

gdata-client-1.0.jar
gdata-core-1.0.jar
gdata-media-1.0.jar
gdata-youtube-2.0.jar
guava-11.0.2.jar
java-mail-1.4.4.jar

I am using the above mentioned library . Please make use of it ; because the ultimate aim is to get the YouTubeService Object. Check below for the code snippet.

package com.baba.test;
/*
* Author : Somanath Nanda
*/


import java.net.MalformedURLException;
import java.net.URL;
import com.google.gdata.client.youtube.YouTubeQuery;
import com.google.gdata.client.youtube.YouTubeService;
public class Test {
private static final String CLIENT_ID = "XXXXXXXX.XXXXX.XXX.XXX";
private static final String DEVELOPER_KEY = "*********************************88";
public static void main(String[] args) throws MalformedURLException {
YouTubeService service = new YouTubeService(CLIENT_ID,DEVELOPER_KEY);
System.out.println("Service : "+service);
}
Litmus
  • 10,558
  • 6
  • 29
  • 44
BaBa Somanath
  • 115
  • 1
  • 9
0

If you're using a build tool, such as Maven, then you could simply do something similar to the following example from a portion of the dependencies section in my pom.xml:

<!-- The mail dependency is required BEFORE the javaee-api dependency.
         The gdata dependency (YouTube API) requires the mail dependency. -->
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.gdata</groupId>
        <artifactId>core</artifactId>
        <version>1.47.1</version>
    </dependency>
Chris Harris
  • 1,329
  • 4
  • 17
  • 28
0

I have added googlecollection-exp.jar into my build path then the previous execption was gone.

Samson Sunny
  • 121
  • 1
  • 3
  • You mean the NoSuchMethod error, right? You might want to expand a little bit on that. Are you sure the stacktrace you got was similar as the one in the question? – rene Sep 21 '15 at 11:15
0

Pay attention to this jar gdata-core-1.0.jar I have the same problem, and I realized I have problem with this jar gdata-core-1.0.jar, and I found from website the same jar gdata-core-1.0.jar, but the content is different. After I replaced the new gdata-core-1.0.jar, problem solved.

So it's tricky that the jar with the same name but their contents are not the same. you thought you have the jar, actually it's not the right one

Nick Liu
  • 1
  • 2
0

It could be that some of your jars would be having dependency on google/guava jars and if they're not in build path or if multiple of them are there it might raise inconsistency hence the error. A quick solution could be add latest version of guava to your pom

 <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>24.0-jre</version>
    </dependency>

Now check in dependency hierarchy if any of your Jar apart from guava is referring to any other older jar of guava/google-collections. If so then exclude it, something like this

<exclusions>
            <exclusion>
                <groupId>com.google.collections</groupId>
                <artifactId>google-collections</artifactId>
            </exclusion>
 </exclusions>
Saurabh Talreja
  • 335
  • 2
  • 6
0

I dont know if its still relevant but i had the same exception

there is a problem with guava 11.02.jar (currently latest version)

when using guava-10.0.1 (can be found here) everything went well.

akub
  • 99
  • 2
  • 10
  • Thanks, yeah, that was already answered. There's a newer version than 9 which works as well: http://code.google.com/p/guava-libraries/wiki/Release10 – kentcdodds Mar 02 '12 at 19:59