java - 调用方法 ".class expected"

标签 java class methods

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

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 预期错误,菜单类编译并运行良好

最佳答案

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

关于java - 调用方法 ".class expected",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13751634/

相关文章:

java - 什么是 Java 中的代理项范围和代理项代码?

python - 是否有实例方法

c# - 如果调用继承的重载,会调用什么方法?

java - 我可以使用什么来为在 tomcat 上运行的 java servlet 中的每个 session 实现后台进程?

java - 在 GridView 组件中显示多个图像时,Android 应用程序崩溃

java - 按钮操作后看不到变量变化

java - 构造函数未定义错误和泛型类

java - 如何在 Java 中将 double 按点拆分为两个十进制数?

swift - 没有参数的方法正在调用参数

java - 我可以对不同但可比较的输入使用相同的方法吗?