gpt4 book ai didi

java - 不让我运行该应用程序

转载 作者:行者123 更新时间:2023-12-01 17:04:35 24 4
gpt4 key购买 nike

package aaa;

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.stage.Stage;

public class pear {

public class aaa extends Application{
@Override
public void start(Stage primaryStage){
Button okbt = new Button("ok");
Scene scene = new Scene(okbt, 200,250);
primaryStage.setTitle("n");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args){
Application.launch(args);
}
}
}

这是我的教科书上为我提供的代码示例,我尝试运行它,但它无法运行。这是错误:

Error: Main method not found in class aaa.pear, please define the main method as:   public static void main(String[] args).

我不明白为什么它是错误的,因为主类位于启动类之外并且在扩展应用程序内部。这直接来自一本书,我只需要知道为什么它无法运行。

最佳答案

static 方法只能在静态或顶级类中声明,而不能在非静态嵌套类中声明。在这种情况下,使用后者更简单

public class MyPearApp extends Application {

public static void main(String[] args){
...
}
}

关于java - 不让我运行该应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26265622/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com