4 Replies Latest reply: Oct 17, 2012 2:38 PM by user2969435 RSS

    Problem on Compiling the JavaFX/FXML project with the default code

      I just installed NetBeans 7.1.2, and JDK 7U4 and JavaFX2.1 Runtime, JavaFX2.1 SDK., then I used NetBeans to create a new JavaFx project with the default code, ans it ran fine to give "Hello World" on the console. Good... Then I used NetBeans to create a new JavaFX/FXML project with the default code -- Sample.java, Sample.fxml, and the main program, but then I got problem when I ran it. Please can someone tell me what gent wrong with my case. The following is the output on the console :
      Created dir: C:\FXML Code\MyFXML002\build
      Updating property file: C:\FXML Code\MyFXML002\build\built-jar.properties
      Created dir: C:\FXML Code\MyFXML002\build\classes
      Created dir: C:\FXML Code\MyFXML002\build\empty
      Created dir: C:\FXML Code\MyFXML002\build\generated-sources\ap-source-output
      Compiling 1 source file to C:\FXML Code\MyFXML002\build\classes
      Exception in Application start method
      Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
           at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
           at com.sun.javafx.application.LauncherImpl.access$000(Unknown Source)
           at com.sun.javafx.application.LauncherImpl$1.run(Unknown Source)
           at java.lang.Thread.run(Thread.java:722)
      Caused by: java.lang.IllegalStateException: Location is not set.
           at javafx.fxml.FXMLLoader.load(Unknown Source)
           at javafx.fxml.FXMLLoader.load(Unknown Source)
           at javafx.fxml.FXMLLoader.load(Unknown Source)
           at javafx.fxml.FXMLLoader.load(Unknown Source)
           at javafx.fxml.FXMLLoader.load(Unknown Source)
           at javafx.fxml.FXMLLoader.load(Unknown Source)
           at myfxml002.MyFXML002.start(MyFXML002.java:25)
           at com.sun.javafx.application.LauncherImpl$5.run(Unknown Source)
           at com.sun.javafx.application.PlatformImpl$4.run(Unknown Source)
           at com.sun.javafx.application.PlatformImpl$3.run(Unknown Source)
           at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
           at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
           at com.sun.glass.ui.win.WinApplication$2$1.run(Unknown Source)
           ... 1 more
      Exception in thread "Thread-2" Java Result: 1
      成功生成(总时间:3 秒)

      The following are the copies of the code generated by NetBeans, none of them is my code.

      1. MyFXML002.java---

      package myfxml002;

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

      * @author Administrator
      public class MyFXML002 extends Application {

      public static void main(String[] args) {
      Application.launch(MyFXML002.class, args);

      public void start(Stage stage) throws Exception {
      Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
      stage.setScene(new Scene(root));

      2. Sample.java---

      package myfxml002;

      import java.net.URL;
      import java.util.ResourceBundle;
      import javafx.event.ActionEvent;
      import javafx.fxml.FXML;
      import javafx.fxml.Initializable;
      import javafx.scene.control.Label;

      * @author Administrator
      public class Sample implements Initializable {

      private Label label;

      private void handleButtonAction(ActionEvent event) {
      System.out.println("You clicked me!");
      label.setText("Hello World!");

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

      3. Sample.fxml---

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

      <?import java.lang.*?>
      <?import javafx.scene.*?>
      <?import javafx.scene.control.*?>
      <?import javafx.scene.layout.*?>

      <AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml" fx:controller="myfxml002.Sample">
      <Button id="button" layoutX="126" layoutY="90" text="Click Me!" onAction="#handleButtonAction" fx:id="button" />
      <Label id="label" layoutX="126" layoutY="120" minHeight="16" minWidth="69" prefHeight="16" prefWidth="69" fx:id="label" />

      Edited by: 933639 on 2012-5-11 下午9:06