Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

java - javafx open window no effect.application launch with then throw class not found


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First you should try to create a minimalistic example to find where the issue is present. Next time please consider creating a reproducible example, so the community can help (debug) better.

The "start()" method is called on the JavaFX Application Thread, when the system is ready for the application to begin running. You can not do JavaFX stuff outside of this thread, which is probably the reason for your crash. I read you are not sure if "start" is useful, but it is absolutely necessary for this reason.

From where are you launching the plugstart method? If it is being launched outside your JavaFX Application Thread (so currently outside of override "start()" entry method) the application will crash.

Here is a reproducible example of a JavaFX application.

package sample;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        // Launch all your JavaFX code and methods from inside this Entry Point function.
        Stage stage = new Stage();
        Scene scene = new Scene(new Label("I am a label object"));
        stage.setScene(scene);
        stage.show();
    }


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

Notice that the JavaFX code is being launched from inside the "start" method (so stage and scene are created there, etc), not from your "main" method. You only have to call "launch(args)" once from the main method, when you want your JavaFX application to start.

You say you already launched the app, presumably from the main method. Why are you attempting to launch it in both the "start" and "plugstart" method? That will definitely cause a crash, especially since it is already running when the "start" method is called.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...