无法在包中找到课程 [英] Not able to find a class in package
本文介绍了无法在包中找到课程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请考虑程序包层次结构folder1/hi
. folder1
包含A.java,hi
包含B.java.
Consider a package hierarchy folder1/hi
. folder1
contains A.java and hi
contains B.java.
B.java:
package aa.pkg;
public class B { }
A.java:
package hi.aa.pkg;
public class A {B b; }
现在B.java成功编译,但是A.java无法编译.
Now B.java compiles successfully, but A.java does not.
我正在cmd中使用这些命令(如果当前目录为folder1
):
I am using these commands in cmd (if the current directory is folder1
):
javac -d hi hi/B.java
javac -cp hi -d . A.java
它说没有找到B级.
编译A.java的正确cmd命令是什么?或者使该代码工作的代码应该是什么样?
What is the correct cmd commands to compile A.java or what should the code look like for this to work?
推荐答案
您必须将B类导入到A类中,因为这两个类位于不同的程序包中.
You have to import class B into Class A. because both classes are in different packages.
package hi.aa.pkg;
import aa.pkg.B;
public class A {B b; }
这篇关于无法在包中找到课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文