I am very new to this and I have a problem with this message that I get every time I try to run a program. I've tried a thousand things and I don't know what else to do. If anyone could help me I would appreciate it.
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at [email protected]/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at [email protected]/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1135)
Caused by: java.lang.RuntimeException: Exception in Application start method
at [email protected]/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
at [email protected]/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: javafx.fxml.LoadException:
/C:/Users/usuario/Documents/ECLIPSE/Saludador/bin/hola/hellofx.fxml:9
at [email protected]/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2722)
at [email protected]/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:935)
at [email protected]/javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:983)
at [email protected]/javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:230)
at [email protected]/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:757)
at [email protected]/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2853)
at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2649)
at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2563)
at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3376)
at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3332)
at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3300)
at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3272)
at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3248)
at [email protected]/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3241)
at hola.Main.start(Main.java:13)
at [email protected]/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
at [email protected]/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at [email protected]/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at [email protected]/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:185)
... 1 more
Caused by: java.lang.ClassNotFoundException: hellofx.Controller
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
at [email protected]/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:933)
... 22 more
Exception running application hola.Main
Main
package hola;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage stage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("hellofx.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Controller
package hola;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
public class Controller implements Initializable {
@FXML
private Label greetingLabel;
@FXML
private Button greetButton;
@FXML
private TextField usernameInput;
@FXML
private void handleButtonAction(ActionEvent event) {
String nombre = usernameInput.getText();
greetingLabel.setText("Hola " + nombre);
usernameInput.setText(null);
}
/*public void initializable(URL url, ResourceBundle rb) {
}*/
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub
}
}
fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="hellofx.Controller">
<children>
<AnchorPane prefHeight="200.0" prefWidth="200.0">
<children>
<Label fx:id="greetingLabel" layoutX="105.0" layoutY="271.0" prefHeight="65.0" prefWidth="389.0" />
<Button fx:id="greetButton" layoutX="241.0" layoutY="173.0" mnemonicParsing="false" onAction="#handleButtonAction" prefHeight="53.0" prefWidth="117.0" text="Saludar" />
<TextField fx:id="usernameInput" layoutX="108.0" layoutY="89.0" prefHeight="25.0" prefWidth="389.0" promptText="Introduce tu nombre" />
</children>
</AnchorPane>
</children>
</StackPane>
I'm trying to run a program where when you press a button, it returns a greeting.
Binded controller name is wrong in fxml.
Change it to correct class name with full package name.
from
to