NoSuchMethod 获取 gdata 服务时出错 [英] NoSuchMethod error getting a gdata service

查看:16
本文介绍了NoSuchMethod 获取 gdata 服务时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误:

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)

这来自以下代码:

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

起初,我将每个库都包含在 http://code.google.com/p/gdata-java-client/downloads/list 并且还导入了比我需要的更多的内容.我已经删除了我认为不必要的库(感谢 thinksteep).所以我目前包含的库是以下库:

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

(那里可能有一些图书馆不是必需的......但我已经快要结束了......)我只是想测试获得 YouTube 服务,以便我可以在这个项目上进行,但没有骰子.哦,我还包含了这个库:http://code.google.com/p/guava-libraries 因为在我收到 NoClassDefFound 错误之前,包含该库似乎可以解决它.预先感谢您的帮助!哦,我也在 gdata 入门指南.最后我的测试构建成功了...再次感谢!

(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!

推荐答案

添加超过要求也可能导致问题.java.lang.NoSuchMethodError 错误通常发生在运行时找不到具有确切签名的所需方法的情况下.可能的原因有:

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.

这篇关于NoSuchMethod 获取 gdata 服务时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆