简体   繁体   中英

Javafx application cannot find the liberay

In my eclipse i have followed the following steps:

  1. New -> Other -> Javafx project

  2. Name the project ie "TestJavaFx"

  3. Create new class "Main"

write the following code:

    public class Main extends Application{

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }

}

And i get an error saying:

Application cannot be resolved to a type

And there is no import.

it looks like i don't have the lib. But how can i create a new Javafx project without having the lib?

How do i fix this?

First in Eclipse you need add jfxrt.jar to project's libraries (It is located in Jre lib folder).

Then you need to override Application's abstract method start

public void start(Stage primaryStage) { 
    primaryStage.show();
}

Here is a minimal example:

import javafx.application.Application;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) {
        primaryStage.show();
    }

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM