Reputation: 17
I'm not able to run this code. I got this from oracle tutorials.
It's a simple hello world application.earlier I wasn't able to compile it but now after including the path for jfxrt.jar
file in classpath I'm able to compile but now not able to run.
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
class A extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler < ActionEvent > () {
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
}
I'm getting these following errors :
Exception in Application constructor
Exception in thread "main" java.lang.RuntimeException: Unable to construct Appli
cation instance: class A
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherIm
pl.java:393)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:
47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NoSuchMethodException: A.<init>()
at java.lang.Class.getConstructor0(Class.java:2810)
at java.lang.Class.getConstructor(Class.java:1718)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherIm
pl.java:275)
... 3 more
Help me out,how to resolve this. Thanks
Upvotes: 0
Views: 108
Reputation: 3608
Make your class public
public class A extends Application
then it should work.
Anyway, do you need another import-Statement? I think the import for ActionEvent is missing:
import javafx.event.ActionEvent;
Upvotes: 1