Guava 库无法与 IntelliJ IDEA 一起使用

发布于 2024-12-12 13:38:20 字数 153 浏览 0 评论 0原文

我的 IDEA 10.5.2 突出显示所有有错误的 guava (10.0.1) 类(未找到类)。但代码编译正确。我只有番石榴罐才有这个麻烦。其他罐子的扭曲正确。

我尝试更改guava版本和jdk版本(1.6、1.7)和idea版本但没有结果。

我做错了什么?

My IDEA 10.5.2 hilights all guava (10.0.1) classes with error (no class found). But code is compilling correctly. I have this trouble only with guava jar's. Other jar's warks correctly.

I try to change guava version and jdk version (1.6, 1.7) and idea version but there is no result.

What am i doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

§对你不离不弃 2024-12-19 13:38:20

IntelliJ 的索引一定不能看到类文件,即使 javac 是这样。根据项目的设置方式,您的构建过程可能具有与 IntelliJ 索引不同的类路径。不过,至少同样可能的是 IntelliJ 索引中存在一些损坏的条目。无论哪种方式,请执行以下操作:

  1. 从“项目结构”对话框(在“文件”菜单中),转到“库”屏幕并确保 guava jar 或其父文件夹列在您的库之一中
  2. 在同一对话框的“模块”屏幕中,确保上述库已在您的模块中列出。
  3. 退出对话框并单击文件 ->使缓存无效。
  4. 重新启动 IntelliJ。这可能需要一段时间。

根据所提供的信息,我无法确定这是您的问题,但这始终是当库神秘地停止工作时我所经历的步骤(这种情况发生的频率比我希望的要多......)。

IntelliJ's indexes must not be seeing the class files, even if javac is. Depending on how your project is set up, your build process may have a different classpath than IntelliJ's indexes. At least as likely, though, is simply the presence of some corrupt entry in IntelliJ's indexes. Either way, do the following:

  1. From the "Project Structure" dialog (in the File menu), go to the Libraries screen and ensure that the guava jar or its parent folder is listed in one of your libraries
  2. In the same dialog's Modules screen, ensure that the above library is listed in your module.
  3. Exit the dialog and click File -> Invalidate Caches.
  4. Restart IntelliJ. This might take awhile.

With the information given, I can't be sure this is your problem, but it's always the steps I go through when a library mysteriously stops working (which happens more often than I'd like...).

听你说爱我 2024-12-19 13:38:20

[回答这个老问题,因为我在 Idea Community Edition 2019.3.1 中也遇到了这种情况]

对我来说,这是由于 build.gradle 文件中的库版本发生变化,解决方案是重新创建项目在一个新文件夹中


(或者也许我可以删除一些 .idea 或缓存文件夹)。

主要取决于build.gradle文件中库的版本。

就我而言,起初,引用的库版本是早期版本,一切正常。

compile group: 'com.google.guava', name: 'guava', version: 'r05'

后来不得不使用较新版本的库以及这个新版本中的一些类。

compile group: 'com.google.guava', name: 'guava', version: '23.5-jre'

由于 build.gradle 已更新,该项目作为 gradle 任务构建得很好。

IntelliJ 尚未更新 - 尽管通常会在 gradle 文件发生更改后更新。

即使在尝试搞乱文件->项目结构、文件->无效缓存和重新启动等之后......它也没有起作用,最后重新创建项目似乎是一个很好的解决方法。

[Answering this old question as I came across this situation even in Idea Community Edition 2019.3.1]

For me it had been due to a change in the version of the library in the build.gradle file, and the solution was to recreate the project in a fresh folder


(or maybe I could've deleted some .idea or cache folders).

It mainly depends on the version of the library in the build.gradle file.

In my case, at first, the version of the library referred to was an earlier version and everything worked fine.

compile group: 'com.google.guava', name: 'guava', version: 'r05'

Later, had to use a newer version of the library and some classes in this new version.

compile group: 'com.google.guava', name: 'guava', version: '23.5-jre'

Since build.gradle was updated, the project built fine as a gradle task.

IntelliJ hadn't got updated - though usually it does after a change in the gradle file.

Even after trying to mess around with File->Project Structure, and File->Invalidate Cache and Restart, etc... it hadn't worked, and finally recreating the project seemed to be a good workaround.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文