NoSuchMethod error getting a gdata service

笑着哭i 提交于 2019-11-28 08:50:17

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.

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)

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.

BaBa Somanath

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);
}

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>

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!