java – 获取gdata服务时出现NoSuchMethod错误
作者:互联网
我收到以下错误:
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).所以我目前包含的库是以下库:
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 getting started guide中完全遵循了每一步(或至少我是这么认为).我的测试版本在最后成功了…再次感谢!
解决方法:
添加超过要求可能也会引起问题.如果运行时找不到具有精确签名的必需方法,则通常会发生java.lang.NoSuchMethodError错误.可能的原因是:
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.
确保没有发生这种情况.
标签:java,youtube,service,gdata-api,gdata 来源: https://codeday.me/bug/20190713/1447383.html