我正在用Ubuntu 14.04系統上的NetBeans和Scene Builder試驗FMXL。javafx.fxml.LoadException:解決onSelectionChanged錯誤(選項卡)
我有一個非常簡單的應用程序與一種形式,其中有一個TabPane,這與2個選項卡。除了默認選項卡選項之外,沒有其他功能,一次只能選一項。
當我將一個方法設置爲在選項卡選項上,在Scene Builder上,響應onSelectionChanged事件,並在控制器上與fxml文件相關的方法時,會引發異常。 沒有上述代碼,一切正常(即編譯和運行)。 錯誤指向在此處定義的選項卡的XML腳本的屬性。
此問題發生在NB8.1 + SC8.1.1 + JDK1.7中,並且也發生在JDK1.8中;也用NB8.0.2 + SC2.2。
這是我的錯誤還是工具中某處的錯誤?
在此先感謝。
錯誤消息:
Executing /home/pvc/projects/java-tests/JavaFX/JavaFXApplication12/dist/run1743546166/JavaFXApplication12.jar using platform /usr/jdk1.7.0_80/bin/java
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 13 more
Java Result: 1
的代碼:
package javafxapplication12;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
*
* @author pvc
*/
public class JavaFXApplication12 extends Application
{
@Override
public void start(Stage stage) throws Exception
{
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
launch(args);
}
}
package javafxapplication12;
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;
import javafx.scene.control.Tab;
/**
*
* @author pvc
*/
public class FXMLDocumentController implements Initializable
{
@FXML
private Tab tab1Id;
@FXML
void handleOnTabSelected(ActionEvent event) {
System.out.println("tab1 selected");
}
@Override
public void initialize(URL url, ResourceBundle rb)
{
// TODO
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.65" fx:controller="javafxapplication12.FXMLDocumentController">
<children>
<TabPane layoutX="-15.0" layoutY="-55.0" prefHeight="200.0" prefWidth="320.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<tabs>
<Tab fx:id="tab1Id" closable="false" onSelectionChanged="#handleOnTab1Selected" text="tab1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</Tab>
<Tab text="Untitled Tab 2">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</Tab>
</tabs>
</TabPane>
</children>
</AnchorPane>