Java 包不存在错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6375179/
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
Java Package Does Not Exist Error
提问by algorithmicCoder
So there's a folder /usr/share/stuff
in the root directory
所以/usr/share/stuff
在根目录下有一个文件夹
in stuff there are a bunch of java files with package org.name
definitions at the top
在东西中有一堆java文件,package org.name
顶部有定义
I am running javac test.java
where test.java
is in a subdomain
我正在运行子域中的javac test.java
where test.java
is
I added /usr/share/stuff
to my class path.
我添加/usr/share/stuff
到我的类路径。
and at the top of test.java
I add import org.name
在test.java
我添加的顶部import org.name
But I get a package does not exist
error...why?
但是我得到一个package does not exist
错误...为什么?
采纳答案by Bruno
Are they in the right subdirectories?
它们是否在正确的子目录中?
If you put /usr/share/stuff
on the class path, files defined with package org.name
should be in /usr/share/stuff/org/name
.
如果你放在/usr/share/stuff
类路径上,定义的文件package org.name
应该在/usr/share/stuff/org/name
.
EDIT: If you don't already know this, you should probably read this: http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/classpath.html#Understanding
编辑:如果您还不知道这一点,您可能应该阅读以下内容:http: //download.oracle.com/javase/1.5.0/docs/tooldocs/windows/classpath.html#Understanding
EDIT 2: Sorry, I hadn't realised you were talking of Java source files in /usr/share/stuff
. Not only they need to be in the appropriate sub-directory, but you need to compile them. The .java
files don't need to be on the classpath, but on the source path. (The generated .class
files need to be on the classpath.)
编辑 2:抱歉,我没有意识到您在谈论 .java 文件中的 Java 源文件/usr/share/stuff
。它们不仅需要位于适当的子目录中,而且您还需要编译它们。这些.java
文件不需要在类路径上,而是在源路径上。(生成的.class
文件需要在类路径上。)
You might get away with compiling them if they're not under the right directory structure, but they should be, or it will generate warnings at least. The generated class files will be in the right subdirectories (wherever you've specified -d
if you have).
如果它们不在正确的目录结构下,您可能会逃脱编译,但它们应该是,否则至少会生成警告。生成的类文件将位于正确的子目录中(-d
如果您有指定,则无论您在何处指定)。
You should use something like javac -sourcepath .:/usr/share/stuff test.java
, assuming you've put the .java
files that were under /usr/share/stuff
under /usr/share/stuff/org/name
(or whatever is appropriate according to their package names).
你应该使用类似javac -sourcepath .:/usr/share/stuff test.java
,假设你已经把.java
那名文件下/usr/share/stuff
下/usr/share/stuff/org/name
(或任何根据合适的是自己的包名)。
回答by pajton
You need to have org/name
dirs at /usr/share/stuff
and place your org.name
package sources at this dir.
你需要有org/name
目录/usr/share/stuff
并将你的org.name
包源放在这个目录中。
回答by Xenland
I had the exact same problem when manually compiling through the command line, my solution was I didn't include the -sourcepath directory so that way all the subdirectory java files would be compiled too!
通过命令行手动编译时我遇到了完全相同的问题,我的解决方案是我没有包含 -sourcepath 目录,这样所有子目录 java 文件也将被编译!
回答by António Almeida
I was having this problem, while trying to use a theme packaged as .jar
in my app, it was working while debugging the app, but it didn't when building/exporting the app.
我遇到了这个问题,在尝试使用.jar
我的应用程序中打包的主题时,它在调试应用程序时工作,但在构建/导出应用程序时却没有。
I solved it by unzipping the jar
, and manually add its contents to my build folder, resulting in this:
我通过解压缩 解决了这个问题jar
,并手动将其内容添加到我的构建文件夹中,结果如下:
project/
│
├── build
│ └── classes
│ ├── pt
│ │ └── myAppName ...
│ └── com
│ └── themeName ...
├── src
└── lib
I don't have the error anymore and my app loads with the intended theme.
我不再有错误,我的应用程序加载了预期的主题。
回答by Mewan
Right click your maven project in bottom of the drop down list Maven >> reimport
右键单击下拉列表底部的 Maven 项目 Maven >> reimport
it works for me for the missing dependancyies
它适用于我缺少的依赖
回答by Rishabh Sagar
If you are facing this issue while using Kotlinand have
如果您在使用Kotlin 时遇到这个问题并且有
kotlin.incremental=true
kapt.incremental.apt=true
in the gradle.properties, then you need to remove this temporarily to fix the build.
在gradle.properties 中,那么您需要暂时删除它以修复构建。
After the successful build, you can again add these properties to speed up the build time while using Kotlin.
成功构建后,您可以再次添加这些属性以加快使用 Kotlin 时的构建时间。