主"螺纹&QUOT Google+的API例外; java.lang.NoClassDefFoundError的:COM /谷歌/普通/基/ preconditions [英] Google+ API Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Preconditions

查看:225
本文介绍了主"螺纹&QUOT Google+的API例外; java.lang.NoClassDefFoundError的:COM /谷歌/普通/基/ preconditions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行谷歌的开发者网站上给出的YouTubeSample。我在code无差错,我的进口似乎是罚款。但是当我运行该项目,我得到上述错误。

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.

任何帮助是AP preciated。下面是完整的类

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:

  • Apache HTTP Client version 4.0.3
  • Google Guava version r09
  • Jackson version 1.6.7
  • Google GSON version 1.6

在这种情况下,它看起来像它的番石榴其中缺失。我不知道你的意思导出番石榴什么,但如果您在当你运行code类路径的番石榴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.

这篇关于主&QUOT;螺纹&QUOT Google+的API例外; java.lang.NoClassDefFoundError的:COM /谷歌/普通/基/ preconditions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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