Guava 库无法与 IntelliJ IDEA 一起使用
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IntelliJ 的索引一定不能看到类文件,即使 javac 是这样。根据项目的设置方式,您的构建过程可能具有与 IntelliJ 索引不同的类路径。不过,至少同样可能的是 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:
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...).
[回答这个老问题,因为我在 Idea Community Edition 2019.3.1 中也遇到了这种情况]
对我来说,这是由于 build.gradle 文件中的库版本发生变化,解决方案是重新创建项目在一个新文件夹中
(或者也许我可以删除一些 .idea 或缓存文件夹)。
主要取决于build.gradle文件中库的版本。
就我而言,起初,引用的库版本是早期版本,一切正常。
后来不得不使用较新版本的库以及这个新版本中的一些类。
由于 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.
Later, had to use a newer version of the library and some classes in this new version.
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.