在JavaFX Scene Builder 2中导入自定义组件jar文件时没有可用的组件

时间:2015-04-06 18:17:35

标签: java javafx-8 scenebuilder

我按照this教程将.jar文件导入Scene Builder 2.选择要导入的jar后,导入对话框没有显示任何组件(作者的导入对话框显示了他的CommodityImageLabel组件)。

这是我的FXML文件:

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

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

<fx:root prefHeight="45.0" prefWidth="45.0" type="AnchorPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="plugin.Scrabble_GUI.view.Tile">
   <children>
      <Label id="1" fx:id="letterLabel" layoutX="16.0" layoutY="11.0" text="A">
         <font>
            <Font size="20.0" />
         </font>
      </Label>
      <Label id="2" fx:id="valueLabel" layoutX="33.0" layoutY="27.0" text="4" />
   </children>
</fx:root>

这是.java文件:

package plugin.Scrabble_GUI.view;

import java.io.IOException;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;

public class Tile extends AnchorPane {
    @FXML
    protected Label letterLabel;
    @FXML
    protected Label valueLabel;

    public Tile() {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("Tile.fxml"));

        loader.setRoot(this);
        loader.setController(this);

        try {
            loader.load();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void setLetter(String s) {
        letterLabel.setText(s);
    }

    public void setValue(String s) {
        valueLabel.setText(s);
    }

}

编辑:

罐子分析报告:

Exception for: plugin/Scrabble_GUI/view/Tile.class
javafx.fxml.LoadException: 
unknown path

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2617)
    at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2864)
    at javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2708)
    at javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2677)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2517)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2425)
    at com.oracle.javafx.scenebuilder.kit.library.util.JarExplorer.instantiateWithFXMLLoader(JarExplorer.java:105)
    at com.oracle.javafx.scenebuilder.kit.library.util.JarExplorer.exploreEntry(JarExplorer.java:146)
    at com.oracle.javafx.scenebuilder.kit.library.util.JarExplorer.explore(JarExplorer.java:65)
    at com.oracle.javafx.scenebuilder.kit.library.user.LibraryFolderWatcher.exploreAndUpdateLibrary(LibraryFolderWatcher.java:298)
    at com.oracle.javafx.scenebuilder.kit.library.user.LibraryFolderWatcher.runDiscovery(LibraryFolderWatcher.java:122)
    at com.oracle.javafx.scenebuilder.kit.library.user.LibraryFolderWatcher.run(LibraryFolderWatcher.java:88)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.ClassNotFoundException: plugin.Scrabble_GUI$view$Tile
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at javafx.fxml.FXMLLoader.loadTypeForPackage(FXMLLoader.java:2932)
    at javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:2921)
    at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2862)
    ... 11 more

编辑2:

Exception for: plugin/scrabble_gui/view/Tile.class
javafx.fxml.LoadException: 
unknown path:2

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2617)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2595)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2425)
    at com.oracle.javafx.scenebuilder.kit.library.util.JarExplorer.instantiateWithFXMLLoader(JarExplorer.java:105)
    at com.oracle.javafx.scenebuilder.kit.library.util.JarExplorer.exploreEntry(JarExplorer.java:146)
    at com.oracle.javafx.scenebuilder.kit.library.util.JarExplorer.explore(JarExplorer.java:65)
    at com.oracle.javafx.scenebuilder.kit.library.user.LibraryFolderWatcher.exploreAndUpdateLibrary(LibraryFolderWatcher.java:298)
    at com.oracle.javafx.scenebuilder.kit.library.user.LibraryFolderWatcher.runDiscovery(LibraryFolderWatcher.java:122)
    at com.oracle.javafx.scenebuilder.kit.library.user.LibraryFolderWatcher.run(LibraryFolderWatcher.java:88)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.IllegalStateException: Location is not set.
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
    at plugin.scrabble_gui.view.Tile.<init>(Tile.java:25)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at java.lang.Class.newInstance(Class.java:433)
    at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
    at javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:1010)
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2723)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
    ... 8 more


Exception for: plugin/Scrabble_GUI/view/Tile.class
javafx.fxml.LoadException: 
unknown path

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2617)
    at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2864)
    at javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2708)
    at javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2677)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2517)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2425)
    at com.oracle.javafx.scenebuilder.kit.library.util.JarExplorer.instantiateWithFXMLLoader(JarExplorer.java:105)
    at com.oracle.javafx.scenebuilder.kit.library.util.JarExplorer.exploreEntry(JarExplorer.java:146)
    at com.oracle.javafx.scenebuilder.kit.library.util.JarExplorer.explore(JarExplorer.java:65)
    at com.oracle.javafx.scenebuilder.kit.library.user.LibraryFolderWatcher.exploreAndUpdateLibrary(LibraryFolderWatcher.java:298)
    at com.oracle.javafx.scenebuilder.kit.library.user.LibraryFolderWatcher.runDiscovery(LibraryFolderWatcher.java:122)
    at com.oracle.javafx.scenebuilder.kit.library.user.LibraryFolderWatcher.run(LibraryFolderWatcher.java:88)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.ClassNotFoundException: plugin.Scrabble_GUI$view$Tile
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at javafx.fxml.FXMLLoader.loadTypeForPackage(FXMLLoader.java:2932)
    at javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:2921)
    at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2862)
    ... 11 more

将包名称更改为scrabble_gui后,这是JAR分析报告。 SceneBuilder现在尝试导入两个jar - 我做了一些代码更改并为该jar使用了一个新名称。

我改变了行

FXMLLoader loader = new FXMLLoader(getClass().getResource("Tile.fxml"));

FXMLLoader loader = new FXMLLoader();

    loader.setLocation(Tile.class.getResource("Tile.fxml"));

0 个答案:

没有答案