线程“main"中的 Google+ API 异常java.lang.NoClassDefFoundError: com/google/common/base/Preconditions [英] Google+ API Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Preconditions

查看:51
本文介绍了线程“main"中的 Google+ API 异常java.lang.NoClassDefFoundError: com/google/common/base/Preconditions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行谷歌开发者网站上提供的 YouTubeSample.我的代码中没有错误,我的导入似乎没问题.但是当我运行该项目时,我收到了上述错误.

I am running the YouTubeSample given on the google developers website. I have no errors in the code and my imports appear to be fine. But when I run the project I get the aforementioned error.

我进行了一些搜索,但老实说我一直无法弄清楚问题是什么.我已经尝试导入外部 jar 番石榴,但没有帮助.

I have done some searches but to be honest I have been unable to work out what the problem is. I have already tried importing an external jar guava but it didn't help.

感谢任何帮助.这是完整的课程

Any help is appreciated. Here is the full class

package com.pengilleys.googlesamples;
import java.io.IOException;
import java.util.List;

import com.google.api.client.googleapis.GoogleHeaders;
import com.google.api.client.googleapis.json.JsonCParser;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.client.util.Key;

public class YouTubeSample {

 public static class VideoFeed {
@Key List<Video> items;
}

public static class Video {
@Key String title;
@Key String description;
@Key Player player;
}

public static class Player {
@Key("default") String defaultUrl;
}

public static class YouTubeUrl extends GenericUrl {
@Key final String alt = "jsonc";
@Key String author;
@Key("max-results") Integer maxResults;

YouTubeUrl(String url) {
  super(url);
}
}

public static void main(String[] args) throws IOException {
// set up the HTTP request factory
HttpTransport transport = new NetHttpTransport();
final JsonFactory jsonFactory = new JacksonFactory();
HttpRequestFactory factory = transport.createRequestFactory(new    HttpRequestInitializer() {

  @Override
  public void initialize(HttpRequest request) {
    // set the parser
    JsonCParser parser = new JsonCParser();
    parser.jsonFactory = jsonFactory;
    request.addParser(parser);
    // set up the Google headers
    GoogleHeaders headers = new GoogleHeaders();
    headers.setApplicationName("Google-YouTubeSample/1.0");
    headers.gdataVersion = "2";
    request.headers = headers;
  }
});
// build the YouTube URL
YouTubeUrl url = new YouTubeUrl("https://gdata.youtube.com/feeds/api/videos");
url.author = "searchstories";
url.maxResults = 2;
// build the HTTP GET request
HttpRequest request = factory.buildGetRequest(url);
// execute the request and the parse video feed
VideoFeed feed = request.execute().parseAs(VideoFeed.class);
for (Video video : feed.items) {
  System.out.println();
  System.out.println("Video title: " + video.title);
  System.out.println("Description: " + video.description);
  System.out.println("Play URL: " + video.player.defaultUrl);
}

}

推荐答案

设置文档 提供了依赖项列表:

根据您正在构建的应用程序,您可能还需要这些依赖项:

Depending on the application you are building, you may also need these dependencies:

在这种情况下,看起来缺少 Guava.我不知道你说的出口"是什么意思?Guava,但是如果您在运行代码时在类路径中包含 Guava r09 jar 文件,应该没问题.

In this case, it looks like it's Guava which is missing. I don't know what you mean about "exporting" Guava, but if you include the Guava r09 jar file in the classpath when you're running the code, it should be fine.

这篇关于线程“main"中的 Google+ API 异常java.lang.NoClassDefFoundError: com/google/common/base/Preconditions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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