我正在尝试使用烧烤条形码打印库。我通过project structure add library成功将库添加到IntelliJ。然后我导入了包并编写了方法,这没有给我任何错误。这些包在类中可用。
但是当我编译时,它会给我一个错误:
error: package net.sourceforge.barbecue does not exist
这怎么可能呢?
我在ubuntu中编码,还有其他地方需要添加库吗?
我正在尝试使用烧烤条形码打印库。我通过project structure add library成功将库添加到IntelliJ。然后我导入了包并编写了方法,这没有给我任何错误。这些包在类中可用。
但是当我编译时,它会给我一个错误:
error: package net.sourceforge.barbecue does not exist
这怎么可能呢?
我在ubuntu中编码,还有其他地方需要添加库吗?
当前回答
这里发生的情况是特定的包在缓存中不可用。重置将有助于解决问题。
File ->使缓存失效/重新启动 转到终端,重新构建项目 。/ gradlew构建
这将再次下载所有丢失的包
其他回答
我在IntelliJ 2020.3中遇到了这个问题,并尝试了无效缓存选项并重新构建,但问题仍然存在。唯一修复它的方法是重命名包,并将其重命名为原来的样子。
无效缓存为我工作,但它太长时间来恢复缓存,所以我没有耐心等待它。我找到了另一种方法来解决我的问题。“修复IDE”步骤3(删除包搜索项目缓存)为我完美地工作
如果您向项目结构中添加了一个库(而不是通过maven,这是不同的),请确保它是作为相关模块的依赖项包含的。
项目结构->模块->依赖项
我在2022.1.4版本遇到了同样的情况。我尝试了第一个答案的所有解决方案,除了删除“。想法”文件夹中。 即使很多朋友都提到了这个解决方案,我也找不到这个文件夹,我到处找用户配置文件和AppData文件夹。这个文件夹实际上是在项目文件夹本身下创建的。
我关闭了项目,删除这个文件夹后重新打开。一切都恢复正常了。感觉就像“英特尔”丢失了,IDE只是“lij”一段时间。哈哈
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.