Хорошо, поэтому у меня есть файл с именем «Sandwich.java» в корневой папке и файл с именем «SandwichType.java» внутри папки в [root] / MyFrstPkg. По какой-то причине он не скомпилирует, утверждая, что Sandwich.java не может быть найден. Вот структура каталогов:
root --
|
|- Sandwich.java
|
|-MyFirstPkg
|
|-SandwichType.java
Вот Сэндвич.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: