Java Netbeans:“包不存在”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35361254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 00:03:43  来源:igfitidea点击:

Java Netbeans: 'Package does not exist'

javanetbeans

提问by user5903893

I have a problem with my code, even though it hasn't been modified in any way. It just suddenly threw this message. As you can see on the left, that they are all in the correct package, and have correct names.
What can I do to fix this problem?

我的代码有问题,即使它没有以任何方式修改。它只是突然抛出了这个消息。正如您在左侧看到的,它们都在正确的包中,并且具有正确的名称。
我能做些什么来解决这个问题?

enter image description here

在此处输入图片说明

回答by itzmebibin

Clearthe cache to fix it. In Windows, cache is located at:

清除缓存以修复它。在 Windows 中,缓存位于:

C:\Users\username\AppData\Local\NetBeans\...

On Linux, cache is at:

在 Linux 上,缓存位于:

/home/username/.cache/netbeans/...

After clearing the cache restart netbeans.

清除缓存后重启netbeans。

回答by agcala

If clearing the cache still doesn't work try adding the jar files themselvesinstead of adding the folder. Looks like a bug in Netbeans. I did it that way and worked like a charm.

如果清除缓存仍然不起作用,请尝试添加 jar 文件本身而不是添加文件夹。看起来像 Netbeans 中的一个错误。我就是这样做的,而且工作得非常有魅力。

回答by kmantic

I had some compiled classes from a JAR which I wanted to include in my project. I created a new package, I added the complied classes in and then got this "package does not exist" error when trying to import the new package.

我有一些来自 JAR 的编译类,我想将它们包含在我的项目中。我创建了一个新包,我添加了编译的类,然后在尝试导入新包时出现了这个“包不存在”错误。

If you're adding compiled Java classes and getting this error, here's how I solved it:

如果您添加已编译的 Java 类并收到此错误,我是这样解决的:

  1. Create the package

  2. Add a new (empty) Java Class (.java file) to the package, using the same name as the compiled Java class.

  3. At this point, you should see your broken references to "package does not exist" or to the class file you just added are fixed.

  4. Delete the new .java file and NetBeans should still see the package with the newly added classes.

  1. 创建包

  2. 将新的(空的)Java 类(.java 文件)添加到包中,使用与编译的 Java 类相同的名称。

  3. 此时,您应该看到对“包不存在”或您刚刚添加的类文件的损坏引用已修复。

  4. 删除新的 .java 文件,NetBeans 仍应看到包含新添加类的包。

回答by Robert Snyder

I ran into this problem after we moved our NFS mount point containing my root project directory.

在移动包含我的项目根目录的 NFS 挂载点后,我遇到了这个问题。

It seems there were some references to the old mount point in the .nb-gradledirectory.

似乎有一些对.nb-gradle目录中旧挂载点的引用。

I closed all the projects in Netbeans and terminated Netbeans. I moved .nb-gradleto hidden.nb-gradle(and .nb-gradle-properties to hidden.nb-gradle-properties for good measure). I restarted NetBeans and reopened the root project (which auto-opened the subprojects).

我关闭了 Netbeans 中的所有项目并终止了 Netbeans。我感动.nb-gradlehidden.nb-gradle和.nb-gradle产出的性质以hidden.nb-gradle这个-性能的好办法)。我重新启动了 NetBeans 并重新打开了根项目(它自动打开了子项目)。

The does not existmessage and all cascaded errors went away. A new .nb-gradledirectory was created in the root project directory. The .nb-gradle-propertiesfile was not re-created.

does not exist消息以及所有级联错误,走了。.nb-gradle在根项目目录中创建了一个新目录。.nb-gradle-properties未重新创建该文件。