我的代码在Eclipse中运行时编译但是每当我尝试在命令提示符下运行它时它会抛出错误“无法找到或加载主类菜单”我已经被困在这几个小时但仍然不知道如何解决它所以任何帮助将受到大力赞赏。 switch语句调用不同类中的方法。
import java.util.Scanner;
import classSeperation.Frequency;
import classSeperation.InputFileAndString;
public class Menu {
public static String S="";
public static Scanner Scase = new Scanner(System.in);
//InputFileAndString inp= new InputFileAndString();
//Frequency FR= new Frequency();
public static void main(String[] args) {
Menu mnu= new Menu();
mnu.MainMenu();
}
public void MainMenu(){
System.out.println("Please enter a number");
System.out.println("Enter 0 to exit the program");
System.out.println("Enter 1 for inputting a file name");
System.out.println("Enter 2 for inputting a string");
System.out.println("Enter 3 for test 'I am a man frequency'");
S= Scase.nextLine();
Frequency FR= new Frequency();
switch(S){
default:
System.out.println("Please select a valid option");
MainMenu();
case "0":
System.out.println("Exiting program");
System.exit(0);
case "1":
InputFileAndString inp= new InputFileAndString();
inp.FileImp();
case "2":
FR.Freq();
break;
case "3":
FR.ManFreq();
break;
}
Scase.close();
}
public void SubMenuF(){
System.out.println("Please enter a number");
System.out.println("Enter 0 to exit");
System.out.println("Enter 1 for a graph result");
System.out.println("Enter 2 for character frequencies");
System.out.println("Enter 3 to return to Main Menu");
S= Scase.nextLine();
Frequency FR= new Frequency();
switch(S){
default:
System.out.println("This is not a valid option, please try again");
SubMenuF();
case "0":
System.out.println("Exiting program");
System.exit(0);
case "1":
FR.graph();
break;
case "2":
//Frequency
Frequency.frequencyFile();
break;
case "3":
MainMenu();
}
}
public void SubSubMenu(){
String S="";
Scanner Scase = new Scanner(System.in);
System.out.println("Please enter a number");
System.out.println("Enter 0 to exit the program");
System.out.println("Enter 1 for a graph");
System.out.println("Enter 2 to return to the main menu");
S= Scase.nextLine();
Frequency FR= new Frequency();
switch(S){
default:
System.out.println("This is not a valid option, please try again");
SubSubMenu();
break;
case "0":
System.out.println("Exiting program");
System.exit(0);
case "1":
FR.graph();
break;
case "2":
MainMenu();
}
Scase.close();
}
}
答案 0 :(得分:0)
检查文件名是否与班级名称相同... 例如Menu.java
编译或运行时是错误吗?
What does "Could not find or load main class" mean?
这可能会有所帮助
答案 1 :(得分:-1)
将文件名保存为---- Menu.java ---因为程序执行从main方法开始,您可能使用不同的名称保存它。 检查一次