NoSuchMethod error getting a gdata service

前端 未结 8 840
时光说笑
时光说笑 2020-12-09 14:06

I get the following error:

Exception in thread \"main\" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.of([Ljava/lang/Object;)Lcom/googl         


        
相关标签:
8条回答
  • 2020-12-09 14:42

    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.

    0 讨论(0)
  • 2020-12-09 14:43

    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>
    
    0 讨论(0)
  • 2020-12-09 14:44

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

    0 讨论(0)
  • 2020-12-09 14:45

    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);
    }
    
    0 讨论(0)
  • 2020-12-09 14:52

    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

    0 讨论(0)
  • 2020-12-09 15:00

    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)
    0 讨论(0)
提交回复
热议问题