0

I want a modal window and so I added these lines of code in program:

primaryStage.initOwner(primaryStage);
primaryStage.initModality(Modality.WINDOW_MODAL);

But If I start my program with these lines of code I get an exception:

Exception in Application start method Exception in thread "main"
 java.lang.NoSuchMethodException: P8.Hauptfenster.main([Ljava.lang.String;)
    at java.lang.Class.getMethod(Class.java:1786)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:126)

What is the reason of this exeption?

Main Window:

public class Hauptfenster extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        BorderPane bp = new BorderPane();
        FlowPane fp = new FlowPane();

        Button bild = new Button("Bilderfassung");
        Button audio = new Button("Audioerfassung");

        Bildererfassung bildererfassung = new Bildererfassung();
        bild.setOnAction(event -> bildererfassung.showBilderfassungDialog());

        HBox hb = new HBox();
        hb.setAlignment(Pos.CENTER);
        hb.getChildren().addAll(bild, audio);
        hb.setSpacing(10.0);
        bp.setCenter(hb);

        Scene scene = new Scene(bp, 400, 400);

        primaryStage.initOwner(primaryStage);
        primaryStage.initModality(Modality.WINDOW_MODAL);

        primaryStage.setTitle("Medienverwaltung");
        //primaryStage.initOwner(primaryStage);
        //primaryStage.initModality(Modality.WINDOW_MODAL);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

2. Window:

public class Bildererfassung {

    public void showBilderfassungDialog() {
        Stage stage = new Stage();

        GridPane gp = new GridPane();
        gp.setAlignment(Pos.CENTER);
        gp.setPadding(new Insets(5));
        gp.setHgap(5);
        gp.setVgap(5);

        Label lblTitel = new Label("Titel:");
        gp.setHalignment(lblTitel, HPos.RIGHT);
        Label lblOrt = new Label("Ort:");
        gp.setHalignment(lblOrt, HPos.RIGHT);
        Label lblAufnahmejahr = new Label("Aufnahmejahr:");
        gp.setHalignment(lblAufnahmejahr, HPos.RIGHT);
        TextField tfTitel = new TextField();
        TextField tfOrt = new TextField();
        TextField tfAufnahmejahr = new TextField();
        Button btnNeu = new Button("Neu");
        Button btnAbbrechen = new Button("Abbrechen");
        HBox hb = new HBox();
        hb.getChildren().addAll(btnNeu, btnAbbrechen);
        hb.setPadding(new Insets(10.0, 0.0, 0.0, 0.0));
        hb.setAlignment(Pos.CENTER);
        hb.setSpacing(5.0);

        gp.add(lblTitel, 0, 0);
        gp.add(lblOrt, 0, 1);
        gp.add(lblAufnahmejahr, 0, 2);
        gp.add(tfTitel, 1, 0);
        gp.add(tfOrt, 1, 1);
        gp.add(tfAufnahmejahr, 1, 2);
        gp.add(hb, 1, 3);

        BorderPane bp = new BorderPane();
        bp.setCenter(gp);

        Scene scene = new Scene(bp);
        stage.setScene(scene);
        stage.setTitle("Bilderfassung");
        stage.show();
    }
}
fabian
  • 67,623
  • 12
  • 74
  • 102
Sarah Pöhler
  • 440
  • 1
  • 4
  • 15
  • Your exception means that you try to launch a class (here `Hauptfenster`) that doesn't have a main method – Nicolas Filotto Dec 05 '16 at 17:29
  • I guess that you added it first then you removed it and now you try to run your class again which is not possible anymore – Nicolas Filotto Dec 05 '16 at 17:30
  • ok now I have a main but a new exception:java.lang.IllegalStateException: Cannot set owner for the primary stage at javafx.stage.Stage.initOwner(Stage.java:565) – Sarah Pöhler Dec 05 '16 at 17:32
  • 1
    No owners for the primary stage are allowed. It does not make sense to set the owner of a stage to the stage itself anyways. And the modality will probably cause an issue too. – fabian Dec 05 '16 at 17:34
  • ok now I understood it thanks – Sarah Pöhler Dec 05 '16 at 17:36
  • Note however that this is really an IntelliJ problem: the standard Java runtime *will* run your JavaFX application without a `main(...)` method. Moreover if you deploy it using built-in deployment tools as either a self-contained application bundle or a web start application, it will be "wrapped" with a standard main class that provides a main method anyway. – James_D Dec 05 '16 at 17:46

0 Answers0