我正在尝试使用烧烤条形码打印库。我通过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中编码,还有其他地方需要添加库吗?
当前回答
我的单元测试也遇到了同样的问题。我在我的主分支上创建了测试,在早期,无论我使用的是哪个分支,一切都运行良好。但是当我再次切换到主分支时,测试不再工作了。 帮助我的是:
关闭intellij ->从目录中删除。idea文件->再次通过pom.xml打开项目(idk如果它与你打开项目的方式有关,但第一次当我尝试通过intellij正常打开它时,它仍然不工作)->从右菜单重新加载所有maven项目->重建项目,就是这样,现在一切都工作了
其他回答
我也有同样的问题。我通过应用android-apt插件https://bitbucket.org/hvisser/android-apt来修复它
package com.example;
import com.sun.jna.Library;
import com.sun.jna.Native;
public class C {
public interface Kernel32 extends Library {
public void OutputDebugStringA(String Text);
public void DebugBreak();
public void Sleep(int a);
}
public static int incint(int in1)
{
testpkg.xxxBird.Say("xxxee"); //only use this statement to call external lib
//I don't use "import" statement.
return in1*2;
}
}
我正在使用intellij的想法。 您需要在项目依赖项中添加testpkg路径。
在我的案例中,问题是IntelliJ和settings.xml文件中有不同的存储库目录配置。
检查两个存储库目录是否相同:
IntelliJ(文件>设置>构建,执行,部署>构建工具> Maven)
settings.xml (通常在c:\ users \myuser\。M2或/home/myuser/.m2)
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<localRepository>C:\Users\myuser\.m2\repository</localRepository>
...
</settings>
修复目录后运行:
为所有项目生成文件夹和更新源
重新导入所有maven项目
如果你遇到了非常奇怪的“无法解决java、sun包的问题”,试试下面的方法:
打开项目结构,将项目SDK更改为另一个版本,例如:java 8 -> 9;11->13,等等,直到它重新索引所有jdk的jar。在相同版本的jdk之间切换可能无法工作!(示例:jetbrains jdk11 -> openjdk 11) 打开一个新项目(或创建一个空项目);暂停新项目的索引;关闭旧的;开始索引;打开旧项目,暂停新项目的索引并等待。
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.