Gluon/JavaFX를 처음 사용하려고하지만 런타임에 InvocationTargetException이 발생합니다. 이 사이트와 다른 사이트에서 답변을 검색했지만 각 제안을 시도한 후에도 동일한 문제가 발생했습니다.JavaFX를 사용할 때 InvocationTargetException이 발생했습니다.
홈페이지 :
package Scenes;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class Main extends Application{
public void start(Stage stage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("test.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("asdf");
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
컨트롤러 :
package Scenes;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javafx.scene.control.Button;
public class Controller {
Button kButton;
Button bpButton;
public void initialize() {
}
public static void browseFileK() {
JFileChooser jfc = new JFileChooser();
int returnValue = jfc.showOpenDialog(null);
if(returnValue == JFileChooser.APPROVE_OPTION)
{
File selectedFile = jfc.getSelectedFile();
}
}
public static void browseFileBP() {
JFileChooser jfc = new JFileChooser();
int returnValue = jfc.showOpenDialog(null);
if(returnValue == JFileChooser.APPROVE_OPTION)
{
File selectedFile = jfc.getSelectedFile();
}
}
}
FXML 파일 :
<?xml version="1.0" encoding="UTF-8"?>
<?import com.gluonhq.charm.glisten.control.TextField?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8.0.151" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<children>
<AnchorPane cache="true" maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
<children>
<Label alignment="CENTER" layoutX="155.0" layoutY="177.0" style=" " textAlignment="CENTER" textFill="#9f9f9f" wrapText="false">
<font>
<Font size="18.0" />
</font>
</Label>
<TextField layoutX="21.0" layoutY="47.0" prefHeight="26.0" prefWidth="237.0" text="Select location of Kasasa accounts file" />
<TextField layoutX="21.0" layoutY="118.0" prefHeight="26.0" prefWidth="237.0" text="Select location of Bill Pay accounts file" />
<Button layoutX="294.0" layoutY="48.0" mnemonicParsing="false" text="Browse..." />
<Button layoutX="294.0" layoutY="115.0" mnemonicParsing="false" text="Browse..." />
<Button layoutX="168.0" layoutY="269.0" mnemonicParsing="false" prefHeight="32.0" prefWidth="253.0" text="Generate refund document" />
</children>
</AnchorPane>
</children>
</VBox>
스택 트레이스 :
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
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$154(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
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 Scenes.Main.start(Main.java:14)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
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
fxml 파일을 main과 같은 패키지에 추가하고 fxml 파일 앞에 "/"를 추가하거나 파일 이름을 "Scenes/test.fxml"로 변경하는 것이 가장 일반적으로 권장되는 것 같습니다. 나를 위해 일 해왔다.
실제 오류 및 스택 추적을 포함 할 수 있습니까? – MMAdams
나는 당신이'IDE '를 사용하고 있지 않다고 추측 할 것이다. 'NetBeans' 나'Eclipse'를 다운로드하라고 제안 할 것입니다. – Sedrick
Eclipse를 사용하고 있습니다. 이것은 JavaFX 사용에 대한 나의 첫 번째 시도이며 전문 프로그래머가 아닙니다. –