Wenn ich mein Programm starte passiert folgendes:
Hier der Code:
Ich hoffe, mir kann wer helfen
Code:
Anzahl an Unterrichtsstunden:
3
Anzahl an Unterrichtsstunden:
Exception in Application constructor
Exception in thread "main" java.lang.RuntimeException: Unable to construct Application instance: class MainWindow
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$160(LauncherImpl.java:819)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more
Caused by: java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at MainWindow.<init>(MainWindow.java:17)
... 13 more
Hier der Code:
Java:
import java.util.Scanner;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class MainWindow extends Application {
int numberHouers = 8;
public MainWindow() {
System.out.println("Anzahl an Unterrichtsstunden:");
Scanner scanner = new Scanner(System.in);
numberHouers = scanner.nextInt();
scanner.close();
launch();
}
@Override
public void start(Stage s) throws Exception {
//Parent layout = FXMLLoader.load(new File("res/layout/test.xml").toURI().toURL());
GridPane layout = new GridPane();
layout.gridLinesVisibleProperty().set(true);
Label[] days = new Label[8];
String[] dayNames = new String[] {"Stunde","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag","Sonntag"};
for(int i = 0; i<days.length; i++) {
days[i] = new Label(dayNames[i]);
days[i].setStyle("-fx-background-color: #aaaaff; -fx-border-color:green; -fx-padding: 10; ");
days[i].setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
GridPane.setFillWidth(days[i], true);
GridPane.setFillHeight(days[i], true);
layout.add(days[i], i, 0);
}
Label[] houers = new Label[numberHouers];
for(int i = 0; i<houers.length; i++) {
houers[i] = new Label(i+1+". Stunde");
houers[i].setStyle("-fx-background-color: #aaaaff; -fx-border-color:green; -fx-padding: 10; ");
houers[i].setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
GridPane.setFillWidth(houers[i], true);
GridPane.setFillHeight(houers[i], true);
layout.add(houers[i], 0, i+1);
}
Scene scene = new Scene((layout));
s.setScene(scene);
s.show();
}
}
Java:
public class Main {
public static void main(String[] args) {
new MainWindow();
}
}
Ich hoffe, mir kann wer helfen