好的,我在根文件夾下有一個名爲'Sandwich.java'的文件,在[root]/MyFrstPkg文件夾內有一個名爲'SandwichType.java'的文件。無論出於何種原因,它都不會聲稱Sandwich.java無法找到。下面是目錄結構:ClassNotFoundException Sandwich.Java ...它在哪裏?
root --
|
|- Sandwich.java
|
|-MyFirstPkg
|
|-SandwichType.java
這裏是Sandwich.java:
//note I also tried adding package MyFrstPkg; in this file as well and removing the leading MyFrstPkg. from the import statement below, still no luck.
import MyFrstPkg.SandwichType; //the text 'MyFrstPkg' part is underlined as an error
class Sandwich{
SandwichType type; //the text 'SandwichType' is underlined as an error
public static void main(String[] args){
Sandwich sndwch1 = new Sandwich();
sndwch1.type = SandwichType.HAM; //the text 'SandwichType' is underlined as an error
System.out.println("A HAM costs $"+sndwch1.type.getCost());
System.out.println("and has "+ sndwch1.type.getSlices()+" slices.");
}
}
這裏是SandwichType.java:
package MyFrstPkg;
enum SandwichType{
HAM(0,0f);
SandwichType(int numSlices, float cost){ // constructor - Ryan changed 'numslices' to 'numSlices'
this.numSlices = numSlices;
this.cost = cost;
} //end constructor
private int numSlices; //These are specific to this
private float cost; // enum class...
public int getSlices(){
return numSlices;
}
public float getCost(){
return cost;
}
}//end of SandwichType enum
我在CMD瀏覽到根的位置和運行'java sandwich.java',我得到的只是一個ClassNotFoundExeption Sandwich.Java,爲什麼沒有找到?這是它自己D:
好的我已經把NetBeans全部放在一起,現在我只是使用Notepad ++並嘗試在CMD中使用java編譯,我一直在類未找到錯誤三明治.Java現在,我很困惑。 – BigOmega 2011-03-28 00:30:57