首页 > 解决方案 > 大查询 API 异常

问题描述

我有这个问题

java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;

在使用 Google 的 Big Query API 时。

我正在使用 JSF,GlassFish 4.1。

我的方法抛出异常:

public void process() throws InterruptedException, FileNotFoundException, IOException {
   GoogleCredentials credentials;
    File credentialsPath = new File("/home/jesus_miranda/Downloads/credential2.json");  // TODO: update to your key path.
    try (FileInputStream serviceAccountStream = new FileInputStream(credentialsPath)) {
        credentials = ServiceAccountCredentials.fromStream(serviceAccountStream);
    }
    // Instantiate a client.
    BigQuery bigquery = BigQueryOptions.newBuilder().setCredentials(credentials).build().getService();
    String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
    QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query).build();

    for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {//At this line the program failed.
        for (FieldValue val : row) {
            System.out.printf("%s,", val.toString());
        }
        System.out.printf("\n");
    }
}

请帮助我,我阅读了很多论坛,所有这些都谈到了番石榴版本。我更新并降级了番石榴版本,它仍然无法正常工作。

问候!

标签: javaguava

解决方案


  1. 这个问题似乎是版本不匹配的结果。查看 BigQuery API 的依赖声明并查看正在使用的 Guava 版本。

  2. 也许您正在构建您的应用程序并忘记在您的 jar 中遮蔽/fatjar guava。


推荐阅读