我有兩個方案 一個在目錄/ home /紅帽/文檔/ java1/J1類路徑規範
Demo1.java
package j1;
public class Demo1
{
public void print()
{
System.out.println("hi");
}
}
和其他在目錄/ home /紅帽/文檔/ java1/J
Demo2.java
import j1.*;
public class Demo2
{
Demo2()
{
Demo1 d=new Demo1();
}
}
當我說
javac -classpath /home/redhat/Documents/java1/j1 Demo2.java
我得到以下錯誤
Demo2.java:2: package j1 does not exist
import j1.*;
^
Demo2.java:7: cannot access Demo1
bad class file: /home/redhat/Documents/java1/j1/Demo1.java
file does not contain class Demo1
Please remove or make sure it appears in the correct subdirectory of the classpath.
Demo1 d=new Demo1();
^
2 errors
我想訪問demo1的實例在DEMO2 請幫助。
我不想把它放在同一個目錄 – elle 2010-09-06 07:00:05
謝謝。我知道了。 – elle 2010-09-06 07:07:49