0

I followed this tutorial for importing .jar files into Scene Builder 2. After selecting the jar to import, the import dialog shows no components (the author's import dialog shows his CommodityImageLabel component).

Here's my FXML file:

<?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>

And here's the .java file:

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);
    }

}

EDIT:

The jar analysis report:

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

EDIT 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

This is the JAR Analysis Report after changing the package name to scrabble_gui. The SceneBuilder is trying to import two jars now - I made some code changes and used a new name for that jar.

I changed the line

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

to

FXMLLoader loader = new FXMLLoader();

    loader.setLocation(Tile.class.getResource("Tile.fxml"));
Rory Byrne
  • 923
  • 1
  • 12
  • 22
  • 1
    What error trace does the [JAR Analysis Report](http://stackoverflow.com/questions/29444698/how-to-create-an-fxml-file-for-an-already-created-new-component-in-java-than-add/29444845?noredirect=1#comment47068672_29444845) show? – jewelsea Apr 06 '15 at 18:28
  • @jewelsea I've added it to the OP. – Rory Byrne Apr 06 '15 at 18:30
  • The stack trace entry `plugin.Scrabble_GUI$view$Tile` seems to indicate that it is looking for an inner class within a Scrabble_GUI class (I am not sure why it would do so). Perhaps rename the package to `scrabblegui` from `Scrabble_GUI`, in case there is some weird parsing rules going on with the FXMLLoader where it thinks a capital letter means a class rather than a package (or something like that). – jewelsea Apr 06 '15 at 19:19
  • @jewelsea That doesn't seemed to have helped. The JAR Analysis Report is reporting an IllegalStateException: Location not set. I'll add the full report to the OP. – Rory Byrne Apr 06 '15 at 20:19
  • I didn't mean to rename the jar, I meant to rename the package e.g. in the Java file: `package plugin.Scrabble_GUI.view;` => `package plugin.scrabblegui.view;` and in the fxml: `fx:controller="plugin.Scrabble_GUI.view.Tile"` => `fx:controller="plugin.scrabblegui.view.Tile"`. Also check => does `getClass().getResource("Tile.fxml")` return a null value? i.e. is the Tile.fxml file in the jar under the path: /plugin/scrabblegui/view/Tile.fxml – jewelsea Apr 06 '15 at 21:06
  • 1
    Actually, when reading the custom components portion of [Introduction to FXML](https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/doc-files/introduction_to_fxml.html#custom_components), that example does not use `fx:controller` in the fxml document (instead the controller is associated in code, which you are already doing). So remove `fx:controller` from your fxml. – jewelsea Apr 06 '15 at 21:22
  • @jewelsea Removing `fx:controller` from the FXML seems to have fixed it. I thought I had tried that yesterday, but I mustn't have. Thanks for the help! – Rory Byrne Apr 07 '15 at 15:18

0 Answers0