2017-12-23 5 views
1

프로그램을 실행하는 동안 JavaFX에 FXML 코드가 혼동하는 오류가 있습니다. 이름
먼저 하나 :
javaFx에서 TARGETINVOCATIONEXCEPTION을 (를) 풀려면 어떻게해야합니까?

<?xml version="1.0" encoding="UTF-8"?> 

<?import javafx.scene.*?> 
<?import javafx.geometry.*?> 
<?import javafx.scene.control.*?> 
<?import java.lang.*?> 
<?import javafx.scene.layout.*?> 
<?import javafxapplication5.FXMLDocumentController ?> 
<GridPane fx:controller = "FXMLDocumentController" hgap="10.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="100.0" prefWidth="600.0" vgap="10.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> 
    <columnConstraints> 
     <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> 
     <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> 
    </columnConstraints> 
    <rowConstraints> 
     <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> 
     <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> 
     <RowConstraints maxHeight="20.0" minHeight="8.0" prefHeight="8.0" vgrow="SOMETIMES" /> 
     <RowConstraints maxHeight="12.0" minHeight="0.0" prefHeight="0.0" vgrow="SOMETIMES" /> 
     <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> 
     <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> 
    </rowConstraints> 
    <children> 
     <Label text="Choose gender:" /> 
     <RadioButton mnemonicParsing="false" text="Female" GridPane.rowIndex="2"> 
      <toggleGroup> 
       <ToggleGroup fx:id="gender" /> 
      </toggleGroup> 
     </RadioButton> 
     <RadioButton mnemonicParsing="false" selected="true" text="Male" toggleGroup="$gender" GridPane.rowIndex="1" /> 
     <Button mnemonicParsing="false" onAction="" onMouseClicked="#BClickedActionHandler" text="OK" GridPane.rowIndex="4" /> 
    </children> 
    <padding> 
     <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" /> 
    </padding> 
</GridPane> 

두 번째 파일 이름은 다음과 같습니다 : 포함 FXMLDocumentController.java : 다음 코드가 포함 F2XML.fxml
나는 세 개의 파일이

package javafxapplication5; 

import java.net.URL; 
import java.util.ResourceBundle; 
import javafx.fxml.FXML; 
import javafx.fxml.Initializable; 
import javafx.scene.control.Button; 
import javafx.scene.control.RadioButton; 

public class FXMLDocumentController implements Initializable { 
    @FXML 
    RadioButton Male; 
    @FXML 
    RadioButton Female; 
    @FXML 
    Button OK; 

    @Override 
    public void initialize(URL url, ResourceBundle rb) { 
     // TODO 
    } 

    @FXML 
    public void BClickedActionHandler() { 
     System.out.println("Hello"); 
    } 

} 

그리고 세번째 것은 : JavaFXApplication5.java 이는 포함이 오류를 해결

Executing D:\Java\JavaFXApplication5\dist\run1638782428\JavaFXApplication5.jar using platform C:\Program Files\Java\jdk1.8.0_151\jre/bin/java 
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$154(LauncherImpl.java:182) 
    at java.lang.Thread.run(Thread.java:748) 
Caused by: javafx.fxml.LoadException: 
file:/D:/Java/JavaFXApplication5/dist/run1638782428/JavaFXApplication5.jar!/javafxapplication5/F2XML.fxml 

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601) 
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2543) 
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) 
    at javafxapplication5.JavaFXApplication5.start(JavaFXApplication5.java:23) 
    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 
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[2,1] 
Message: Premature end of file. 
    at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:604) 
    at javax.xml.stream.util.StreamReaderDelegate.next(StreamReaderDelegate.java:88) 
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2513) 
    ... 12 more 
Exception running application javafxapplication5.JavaFXApplication5 
Java Result: 1 

수있는 사람의 도움 :

package javafxapplication5; 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 JavaFXApplication5 extends Application { @Override public void start(Stage stage) throws Exception { Parent root = null; Scene scene = null; FXMLLoader loader = new FXMLLoader(getClass().getResource("F2XML.fxml")); loader.setController(new FXMLDocumentController()); Pane mainPane = loader.load(); scene = new Scene(root); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } } 

내가 다음 코드로 어려움을 겪고 있던 프로그램을 실행하는 경우?

답변

0

은 스택 추적에 바로 거기 말한다 :

Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[2,1] 
Message: Premature end of file. 

이 어떤 당신의 입력 파일 파서가 될 것으로 예상처럼되지 않습니다 것을 의미한다. 파일을 XML 편집기 또는 Internet Explorer에로드하여 파일이 유효한 XML인지 확인하십시오.

0

InvocationTargetExceptions은 컴파일 타임 동안 알려지지 않은 코드가 실행되는 메소드에 던져 지므로 메소드에 의해 던져지는 예외는 throws 절에서 선언되거나 호출시 catch 될 수 없습니다. 따라서 스택 트레이스를 "내려 가서"관련 "원인"블록을 찾아야합니다.

는이 경우 구문 분석 된 XML이 손상 될 것으로 보인다

Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[2,1] 
Message: Premature end of file. 

입니다. 귀하의 질문에 제공 한 XML을 확인하고 나에게 (그리고 그러한 오류의 경우 불평 할 것이 Internet Explorer) 괜찮아 보입니다.

Caused by: javafx.fxml.LoadException: 
file:/D:/Java/JavaFXApplication5/dist/run1638782428/JavaFXApplication5.jar!/javafxapplication5/F2XML.fxml 
:

당신이 여기에 제공된 XML 실제로는 당신이 마지막 "위의"예외 블록에서 볼 수 있듯이에서 읽은 항아리 파일 내에있는 XML 있는지 확인

어쩌면 파일 시스템 내에 XML이 있지만 JavaFXApplication5.jar 뒤에 해당 classpath-entry가 있고 오류의 원인으로 잘못된 XML을보고있는 것일 수 있습니다.

관련 문제