java: 程序包com.google.common.collect不存在
时间: 2023-10-06 21:04:15 浏览: 111
这个错误可能是因为你没有在项目中引入Google Guava库。Google Guava是一个Java库,提供了许多实用的工具类和集合类,可以帮助简化Java开发。如果你使用了Google Guava库中的类,就需要在项目中引入该库。
要引入Google Guava库,可以使用Maven或Gradle等构建工具,在项目的依赖中添加以下内容:
Maven:
```xml
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1.1-jre</version>
</dependency>
```
Gradle:
```groovy
dependencies {
implementation 'com.google.guava:guava:30.1.1-jre'
}
```
如果你不使用构建工具,可以手动下载Google Guava库的jar包,并将其添加到项目的classpath中。
下载地址:https://github.com/google/guava/releases
相关问题
程序包com.google.common.collect不存在
这个问题可能是由于缺少相应的依赖库或者版本不匹配导致的。请检查你的项目依赖是否包含了com.google.common.collect相关的依赖,并且版本是否正确。如果没有,请在你的项目中添加依赖:
```
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.0-jre</version>
</dependency>
```
然后重新编译和运行你的程序。如果问题仍然存在,请检查你的环境配置是否正确,并且确认你的项目构建方式是否正确。
java.lang.NoSuchMethodError: com.google.common.collect.Sets$SetView.iterator()Lcom/google/common/collect/UnmodifiableIterator;
回答: 引发java.lang.NoSuchMethodError异常的原因是在使用Spark-submit提交任务时,调用了com.google.common.collect.Sets.newConcurrentHashSet()方法,但该方法在当前环境中不存在。根据引用\[1\]提供的解决思路,有以下几种方法可以尝试解决该问题。首先,可以检查guava库的版本是否与其他依赖库兼容。其次,可以尝试通过引用\[2\]中的代码来查看当前环境中是否存在com.google.common.collect.Sets类。最后,如果你正在使用curator、zookeeper和guava这三个库,需要确保它们的版本兼容性。根据引用\[3\]中的错误信息,可以看到在使用curator时出现了版本兼容性问题。你可以尝试更新curator和guava的版本,以解决该问题。
#### 引用[.reference_title]
- *1* *2* [java.lang.NoSuchMethodError: com.google.common.collect.Sets.newConcurrentHashSet()异常解决思路](https://blog.csdn.net/fengzheku/article/details/50688044)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor()](https://blog.csdn.net/qq_39900031/article/details/118108535)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]