2014-04-07 8 views
7

मुझे एक समस्या है कि मैं बिल्कुल अपने आप को हल नहीं कर सकता क्योंकि मैंने अभी जावा जावा का उपयोग करना शुरू कर दिया है। मुझे एक बुरा javafx.fxml.LoadException मिलता है:, लेकिन मैंने बिल्कुल एक गाइड की तरह किया है, लेकिन मैं अपना मुख्य भाग नहीं ले सकता।FXML लोड अपवाद

apr 07, 2014 4:06:37 EM application.Main start 
ALLVARLIG: null 
javafx.fxml.LoadException: 
/C:/Users/Jakob/Dropbox/java_kurser/Project%20Timeline/bin/application/LoginGUI.fxml 

    at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.load(Unknown Source) 
    at application.Main.start(Main.java:21) 
    at com.sun.javafx.application.LauncherImpl$8.run(Unknown Source) 
    at com.sun.javafx.application.PlatformImpl$7.run(Unknown Source) 
    at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source) 
    at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.application.PlatformImpl$6.run(Unknown Source) 
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.access$300(Unknown Source) 
    at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[2,6] 
Message: Bearbetningsinstruktionens målmatchning "[xX][mM][lL]" är inte tillåten. 
    at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(Unknown Source) 
    at javax.xml.stream.util.StreamReaderDelegate.next(Unknown Source) 
    ... 20 more 

LoginController.java

package application; 

import java.net.URL; 
import java.util.ResourceBundle; 
import javafx.event.ActionEvent; 
import javafx.event.EventHandler; 
import javafx.fxml.FXML; 
import javafx.fxml.Initializable; 
import javafx.scene.control.Button; 
import javafx.scene.control.PasswordField; 
import javafx.scene.control.TextField; 


public class LoginController implements Initializable { 

    @FXML // ResourceBundle that was given to the FXMLLoader 
    private ResourceBundle resources; 

    @FXML // URL location of the FXML file that was given to the FXMLLoader 
    private URL location; 

    @FXML // fx:id="loginButton" 
    private Button loginButton; // Value injected by FXMLLoader 

    @FXML // fx:id="newUserButton" 
    private Button newUserButton; // Value injected by FXMLLoader 

    @FXML // fx:id="passwordField" 
    private PasswordField passwordField; // Value injected by FXMLLoader 

    @FXML // fx:id="usernameField" 
    private TextField usernameField; // Value injected by FXMLLoader 

    public void initialize(URL location, ResourceBundle resources) { 

     assert loginButton != null : "fx:id=\"loginButton\" was not injected: check your FXML file 'LoginGUI.fxml'."; 
     assert newUserButton != null : "fx:id=\"newUserButton\" was not injected: check your FXML file 'LoginGUI.fxml'."; 
     assert passwordField != null : "fx:id=\"passwordField\" was not injected: check your FXML file 'LoginGUI.fxml'."; 
     assert usernameField != null : "fx:id=\"usernameField\" was not injected: check your FXML file 'LoginGUI.fxml'."; 


     //The button event for the login button 
     loginButton.setOnAction(new EventHandler<ActionEvent>() { 

      public void handle(ActionEvent e) { 
       System.out.println("This button works"); 
      } 
     }); 
     } 
    } 

LoginGUI.fxml

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


<?import java.lang.*?> 
<?import java.util.*?> 
<?import javafx.scene.control.*?> 
<?import javafx.scene.layout.*?> 
<?import javafx.scene.paint.*?> 
<?import javafx.scene.text.*?> 
<?scenebuilder-background-color 0x008effff?> 

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="LoginController"> 
    <children> 
    <Button fx:id="loginButton" cancelButton="false" contentDisplay="CENTER" defaultButton="true" layoutX="254.0" layoutY="263.0" mnemonicParsing="false" opacity="1.0" prefHeight="28.0" prefWidth="92.0" text="Login" underline="false"> 
     <font> 
     <Font size="14.0" fx:id="x1" /> 
     </font> 
    </Button> 
    <PasswordField fx:id="passwordField" layoutX="241.0" layoutY="206.0" prefHeight="23.000099999997474" prefWidth="118.0" promptText="Password" /> 
    <TextField fx:id="usernameField" layoutX="241.0" layoutY="166.0" prefHeight="23.0" prefWidth="118.0" promptText="Username" /> 
    <Label layoutX="248.0" layoutY="98.0" prefHeight="35.000099999997474" prefWidth="105.0" text="Welcome"> 
     <font> 
     <Font size="22.0" /> 
     </font> 
    </Label> 
    <Button id="loginButton" fx:id="newUserButton" cancelButton="false" contentDisplay="CENTER" defaultButton="true" font="$x1" layoutX="254.0" layoutY="313.0" mnemonicParsing="false" opacity="1.0" prefHeight="28.0" prefWidth="92.0" text="New User" underline="false" /> 
    </children> 
</AnchorPane> 

और Main.java

package application; 

import java.util.logging.Level; 
import java.util.logging.Logger; 

import javafx.application.Application; 
import javafx.fxml.FXMLLoader; 
import javafx.scene.Scene; 
import javafx.scene.layout.AnchorPane; 
import javafx.stage.Stage; 

public class Main extends Application { 

    public static void main(String[] args) { 
     Application.launch(Main.class, (java.lang.String[])null); 
    } 

    @Override 
    public void start(Stage primaryStage) { 
     try { 
      AnchorPane root = (AnchorPane) FXMLLoader.load(Main.class.getResource("LoginGUI.fxml")); 
      Scene scene = new Scene(root); 
      primaryStage.setScene(scene); 
      primaryStage.setTitle("Bluerift Timeline"); 
      primaryStage.show(); 
     } catch (Exception ex) { 
      Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); 
     } 
    } 

} 
+0

कृपया अनुवाद करें: Bearbetningsinstruktionens målmatchning "[xX] [mM] [lL]" är inte tillåten। – Puce

+0

प्रसंस्करण निर्देश लक्ष्य मैच ........ की अनुमति नहीं है। और शुरुआत में: ALLVARLIG: शून्य = गंभीर: शून्य – jabbeboy

+1

सुनिश्चित नहीं है कि यह समस्या है, लेकिन मुख्य विधि असामान्य है। आप बस 'लॉन्च (तर्क) कर सकते हैं; '। जो भी आप करते हैं, हालांकि, तर्क सरणी के लिए एक शून्य संदर्भ में गुजरना एक बहुत बुरा विचार है। 'Application.launch (Main.class, नया स्ट्रिंग [0]); यदि आप चाहते थे (कुछ कारणों से) कमांड लाइन तर्कों को अनदेखा करने के लिए मजबूर करना अधिक सुरक्षित होगा। –

उत्तर

11

समस्या में है: यह अपवाद उत्पादन होता है खट्टा ce

तो, आप तो ऐसा कर यह एक उचित एक

को बदलने के लिए, यह एक

AnchorPane root = (AnchorPane) FXMLLoader.load(Main.class.getResource("/packagename/LoginGUI.fxml")); 
0
साथ fxml फ़ाइल यहाँ के स्रोत

AnchorPane root = (AnchorPane) FXMLLoader.load(Main.class.getResource("LoginGUI.fxml")); 

संपादित मिल गया है

मैंने भी इस मुद्दे का अनुभव किया। मैंने पाया कि मैंने पैकेज नाम को FXML फ़ाइल में दिए गए नियंत्रक नाम में नहीं जोड़ा है; मैंने शुरुआत में केवल नियंत्रक वर्ग का नाम जोड़ा। उदाहरण के लिए: यदि मेरा नियंत्रक वर्ग com.stackoverflow.gui पैकेज के अंतर्गत है और मेरा नियंत्रक वर्ग का नाम LoginController है। FXML फ़ाइल में com.stackoverflow.gui.LoginController होना चाहिए और न केवल LoginController

संबंधित मुद्दे