Declaração do @FXML no Java FX

JavaSE

16/10/2019

Olá pessoal, estou fazendo um exemplo simples de um programa que tem uma combobox, ao clicar nele os itens aparecem. Porém se não coloco no FXMLcontroller antes da declaração da combobox o parâmetro @FXML e seu pacote respectivo, ao executar o programa da um erro. Qual é a importância do @FXML, por que quando não declaro o programa da erro? Segue abaixo o erro exibido:

>
Exception in Application start method
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
	at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
	at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
	at java.lang.Thread.run(Thread.java:748)
Caused by: javafx.fxml.LoadException: 
file:/C:/Users/eder/Documents/NetBeansProjects/JavaFXBasico2/dist/run2041392979/JavaFXBasico2.jar!/javafxbasico2/FXMLComboBox.fxml

	at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
	at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
	at javafxbasico2.MainComboBox.start(MainComboBox.java:23)
	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
	at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
	at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(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$3(WinApplication.java:177)
	... 1 more
Caused by: java.lang.NullPointerException
	at javafxbasico2.FXMLComboBoxController.carregarComboBox(FXMLComboBoxController.java:46)
	at javafxbasico2.FXMLComboBoxController.initialize(FXMLComboBoxController.java:33)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
	... 17 more
Exception running application javafxbasico2.MainComboBox
Java Result: 1
Deleting directory C:\Users\eder\Documents\NetBeansProjects\JavaFXBasico2\dist\run2041392979

----
Iooi Sistemas

Iooi Sistemas

Curtidas 0
POSTAR