0

I have a problem with executing my first JavaFX application.

package helloworld;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class HelloWorld extends Application{

    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                System.out.println("Hello World!");
            }
        });

        StackPane root = new StackPane();
        root.getChildren().add(btn);

 Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
 public static void main(String[] args) {
        launch(args);
    }
}

It runs in eclipse but not in the terminal and I have no idea why. I read about similar problems, but the solutions didn't help in my case. When I run this in the helloworld directory:

julians-mbp-2:helloworld Julian$ javac HelloWorld.java 
julians-mbp-2:helloworld Julian$ java HelloWorld

I get an error message, that tells me, in german:

Fehler: Hauptklasse HelloWorld konnte nicht gefunden oder geladen werden

which means:

Error: Main class HelloWorld could not be found or loaded

My Java version should be up to date:

julians-mbp-2:helloworld Julian$ javac -version
javac 1.8.0_45
julians-mbp-2:helloworld Julian$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
julians-mbp-2:helloworld Julian$

Thank you very much and sorry if I'm being stupid.

Julian
  • 19
  • 4
  • The class name is `helloworld.Helloworld`. You must add the package name! – isnot2bad Apr 18 '15 at 21:27
  • do you mean: `julians-mbp-2:helloworld Julian$ javac HelloWorld.java` `julians-mbp-2:helloworld Julian$ java helloworld.HelloWorld` `Fehler: Hauptklasse helloworld.HelloWorld konnte nicht gefunden oder geladen werden` that didn't work. – Julian Apr 18 '15 at 21:45
  • Almost, but not exactly. You're already inside package `helloworld`. Move one level up (`cd ..`) to be on root package level. – isnot2bad Apr 18 '15 at 21:56

0 Answers0