我尝试的一切都不起作用。当我从 fxml 文件中删除控制器类时,除了屏幕不工作外,一切正常。这是我的文件: 请告诉我是否需要提供更多。
package main.userInterfaceLaag;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import main.domeinLaag.*;
import java.time.LocalDate;
public class Main extends Application {
public static void main(String[] args){
Docent docent1 = new Docent("Willem Pietersen", "[email protected]", "12345",
LocalDate.now().minusYears(30), "wpieter", Bevoegdheid.Docent, 12345);
Docent docent2 = new Docent("Jan Willems", "[email protected]", "12345",
LocalDate.now().minusYears(35), "jwillems", Bevoegdheid.Docent, 56789);
docent1.voegDocentToe(docent2);
docent2.voegDocentToe(docent1);
System.out.println(docent1.geefAlleDocenten());
System.out.println(docent1.geefNaam());
Klas klas1 = new Klas("V1A");
Vak vak1 = new Vak(12345, "OOAD");
Vak vak2 = new Vak(54325, "OOP");
Lokaal lokaal1 = new Lokaal("1.035");
Lokaal lokaal2 = new Lokaal("5.993");
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
String fxmlPagina = "LesInvoeren.fxml";
FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlPagina));
Parent root = loader.load();
stage.setTitle("HotelApp");
stage.setScene(new Scene(root));
stage.show();
}
}//缺席
我的控制器类:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-
Infinity" prefHeight="449.0" prefWidth="618.0"
xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="main.userInterfaceLaag.LesInvoeren">
"C:\Program Files\Java\jdk-19\bin\java.exe" --module-path lib --add-modules javafx.controls,javafx.fxml "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2022.3.2\lib\idea_rt.jar=57857:C:\Program Files\JetBrains\IntelliJ IDEA 2022.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\prody\IdeaProjects\Team-skunk-V1A\out\production\Team-skunk-V1A;C:\Users\prody\.m2\repository\org\openjfx\javafx-fxml\19\javafx-fxml-19.jar;C:\Users\prody\.m2\repository\org\openjfx\javafx-fxml\19\javafx-fxml-19-win.jar;C:\Users\prody\.m2\repository\org\openjfx\javafx-controls\19\javafx-controls-19.jar;C:\Users\prody\.m2\repository\org\openjfx\javafx-controls\19\javafx-controls-19-win.jar;C:\Users\prody\.m2\repository\org\openjfx\javafx-graphics\19\javafx-graphics-19.jar;C:\Users\prody\.m2\repository\org\openjfx\javafx-graphics\19\javafx-graphics-19-win.jar;C:\Users\prody\.m2\repository\org\openjfx\javafx-base\19\javafx-base-19.jar;C:\Users\prody\.m2\repository\org\openjfx\javafx-base\19\javafx-base-19-win.jar main.userInterfaceLaag.Main
[main.domeinLaag.Docent@6adede5]
Willem Pietersen
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at javafx.graphics@19/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
at javafx.graphics@19/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1081)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics@19/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
at javafx.graphics@19/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: javafx.fxml.LoadException:
/C:/Users/prody/IdeaProjects/Team-skunk-V1A/out/production/Team-skunk-V1A/main/userInterfaceLaag/LesInvoeren.fxml
at javafx.fxml@19/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2707)
at javafx.fxml@19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2677)
at javafx.fxml@19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
at javafx.fxml@19/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2516)
at main.userInterfaceLaag.Main.start(Main.java:37)
at javafx.graphics@19/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at javafx.graphics@19/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at javafx.graphics@19/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics@19/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics@19/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics@19/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics@19/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
... 1 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:116)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:77)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at javafx.base@19/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml@19/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:84)
at javafx.fxml@19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2673)
... 12 more
Caused by: java.lang.NullPointerException: Cannot invoke "main.domeinLaag.Docent.geefAlleDocenten()" because "this.docent" is null
at main.userInterfaceLaag.LesInvoeren.initialize(LesInvoeren.java:24)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
... 19 more
Exception running application main.userInterfaceLaag.Main
Process finished with exit code 1
enter code here
package main.userInterfaceLaag;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import main.domeinLaag.*;
import java.util.ArrayList;
public class LesInvoeren {
private Docent docent;
private Vak vak;
private Klas klas;
private Lokaal lokaal;
@FXML private ComboBox docentComboBox;
@FXML private ComboBox vakComboBox;
@FXML private ComboBox klasComboBox;
@FXML private ComboBox lokaalComboBox;
public void initialize() {
ObservableList<String> alleNamen = FXCollections.observableArrayList();
for (Docent d: docent.geefAlleDocenten()) {
System.out.println(d.geefNaam());
alleNamen.add(d.geefNaam());
}
docentComboBox.setItems(alleNamen);
// docentComboBox.setItems(FXCollections.observableArrayList(alleNamen));
vakComboBox.setItems(FXCollections.observableArrayList(vak.geefAlleVakken()));
klasComboBox.setItems(FXCollections.observableArrayList(klas.geefAlleKlassen()));
lokaalComboBox.setItems(FXCollections.observableArrayList(lokaal.geefAlleLokalen()));
}
}