我正在尝试使用烧烤条形码打印库。我通过project structure add library成功将库添加到IntelliJ。然后我导入了包并编写了方法,这没有给我任何错误。这些包在类中可用。

但是当我编译时,它会给我一个错误:

error: package net.sourceforge.barbecue does not exist

这怎么可能呢?

我在ubuntu中编码,还有其他地方需要添加库吗?


当前回答

I created two new classes under a new package and used it in rest of the code, Intellij was able to resolve these no red highlights were shown in the intellij editor. While building it was showing package doesn't exist error. I tried everything from gradle clean build, rebuild project, clear .idea and .gradle and reimporting the project, clearing the gradle local cache but nothing was working. Finally I refactored the name of the new package and this time intellij was able to recognize the new classes and it started working.

其他回答

退出IntelliJ,删除所有。idea目录:

rm -Rf **/.idea/ 

并重新启动。

我尝试了所有值得欣赏的答案,但没有一个能解决我的问题!

根据Intellij社区的消息,Maven在2020.1和2020.1.1版本中有一个bug: https://youtrack.jetbrains.com/issue/IDEA-237320?_ga=2.235486722.203129946.1591253608-322129264.1584010541

请尝试在2019.3.4版本上运行(从第一次开始就对我有效)

你可以从这里下载

https://www.jetbrains.com/idea/download/previous.html?_ga=2.190043688.203129946.1591253608-322129264.1584010541

这里发生的情况是特定的包在缓存中不可用。重置将有助于解决问题。

File ->使缓存失效/重新启动 转到终端,重新构建项目 。/ gradlew构建

这将再次下载所有丢失的包

对我来说,唯一有效的方法是:

mvn idea:idea

好处是您不必删除.idea文件夹或.iml文件,从而丢失所有配置。一切都会被保存下来。

(可能有些类似gradle的想法也适用于gradle)。

我在IntelliJ 2020.3中遇到了这个问题,并尝试了无效缓存选项并重新构建,但问题仍然存在。唯一修复它的方法是重命名包,并将其重命名为原来的样子。