Not able to find a class in package

蹲街弑〆低调 提交于 2020-01-03 04:38:29

问题


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; }

Now B.java compiles successfully, but A.java does not.

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

It says class B not found.

What is the correct cmd commands to compile A.java or what should the code look like for this to work?


回答1:


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; }


来源:https://stackoverflow.com/questions/30982793/not-able-to-find-a-class-in-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!