问题描述
我收到以下错误:
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("[email protected]", "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
(可能有一些库是没有必要...但我现在已经结束了......)
我只是想测试获得YouTube服务,这样我就可以了解这个项目,但没有骰子。哦,我还包括这个库:因为在我收到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服务时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!