0

尝试使用以下代码从主类运行 start 方法时:

public class rungame {
    public void run() {
        Menu.start(string[]);
    }
}

我试图运行的方法是:

    public class Menu{

    public static void start(String[] args){
        for( ; ; ){
            System.out.println("\nWelcome To The Block Game By Joe Easton\n");
            System.out.println("Enter S To Start");
            System.out.println("Enter H For Help");
            System.out.println("Enter E To Exit");
            System.out.println("\nWhat is your command?");

            //loop looking for input
            for( ; ; ){

                //private
                String answer;
                Keyboard kb = new Keyboard();
                answer = kb.readString();

                if(answer.charAt(0) == 'S' || answer.charAt(0) == 's' || answer.charAt(0) == 'H' || answer.charAt(0) == 'h' || answer.charAt(0) == 'e' || answer.charAt(0) == 'E') {

                    if(answer.charAt(0) == 'S' || answer.charAt(0) == 's'){
                        System.out.println("\nWhat is your name?");
                        String name;
                        name = kb.readString();

                        System.out.println("\nPress y to start");
                        String start;
                        start = kb.readString();

                        if(answer.charAt(0) == 'y' || answer.charAt(0) == 'Y') {

                        }

                        else{break;
                        }
                    }

                    if(answer.charAt(0) == 'H' || answer.charAt(0) == 'h'){

                                    System.out.println("\nIn this game, you have to avoid the B's by moving your character P. \nThe longer you last, the more points you get. \n\nTo move your character:\nUse the G key to go left\nUse the H key to go right\nUse the J key to go up\nUse the K key to go down");
                                    System.out.println("\nWhat is your command?");
                            }

                    if(answer.charAt(0) == 'E' || answer.charAt(0) == 'e'){
                    System.exit(0);
                    }
                }
                else{System.out.println("\nInvalid Command!");
                System.out.println("\nWhat is your command?");
                }
            }
        }
    }
}

当我尝试从另一个类运行它时出现 .class 预期错误,菜单类编译并运行良好

4

2 回答 2

1

什么是string[],你应该传递有效的实例String[]

于 2012-12-06T20:07:30.560 回答
0

如果您正在运行rungame,那么我怀疑它是如何运行的,因为它没有 main 方法。它确实有一个 run 方法,但该类既不实现Runnable接口也不扩展Thread类。

string[]还有其他人所说的模棱两可。

此外,如果两个类都在同一个文件中,则public单个文件中只能存在 1 个类。如果要将public标识符附加到类,则需要准备单独的文件。

检查以上内容,然后它应该可以正常工作。

于 2012-12-06T20:17:53.473 回答