Can't use icons as a graphic into FXML

Issue #17 resolved
Nathan SALAUN created an issue

Hello,

I've got this piece of FXML code :

<...>
      <Button ...>
            <graphic>
                  <MaterialIcon glyphName="ADB" size="1em" glyphStyle="" />
            </graphic>
      </Button>
</...>

But it doesn't work, it triggers an InstanciationException when parsed by FXMLLoader.

What am I doing wrong ? Is there a way to fix this ?

Thanks !

Comments (12)

  1. Nathan SALAUN reporter

    Here is it :

    javafx.fxml.LoadException: 
    /C:/Users/natinusala/Documents/launchmycraft/workspace/Executable/bin/theme/dialog.fxml:46
    
        at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
        at javafx.fxml.FXMLLoader.access$700(Unknown Source)
        at javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(Unknown Source)
        at javafx.fxml.FXMLLoader$ValueElement.processStartElement(Unknown Source)
        at javafx.fxml.FXMLLoader.processStartElement(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 fr.launchmycraft.launcher.DialogFactory.createDialog(DialogFactory.java:59)
        at fr.launchmycraft.launcher.DialogFactory.createDialog(DialogFactory.java:108)
        at fr.launchmycraft.launcher.ExecutableMain.main(ExecutableMain.java:75)
    Caused by: java.lang.InstantiationException: de.jensd.fx.glyphs.materialicons.MaterialIcon
        at java.lang.Class.newInstance(Unknown Source)
        at sun.reflect.misc.ReflectUtil.newInstance(Unknown Source)
        ... 14 more
    Caused by: java.lang.NoSuchMethodException: de.jensd.fx.glyphs.materialicons.MaterialIcon.<init>()
        at java.lang.Class.getConstructor0(Unknown Source)
        ... 16 more
    
  2. Nathan SALAUN reporter

    My guess is that MaterialIcon is an enum, so there is no public constructor and the instantiation obviously fails.

  3. Jens Deters repo owner

    Thanks! Sorry silly question, but 1. FontAwesomeFX 8.6 is included on the classpath? And 2. there are imports in the FXML, like? <?import de.jensd.fx.glyphs.materialicons.*?>

  4. Nathan SALAUN reporter
    1. Yes it is
    2. I only imported de.jensd.glpyhs.materialicons.MaterialIcon

    But I just figured it out, I have to put MaterialIconView and not MaterialIcon and it works fine. It was my fault, I should have checked it beforehand. Sorry for the inconvenience x)

  5. Nathan SALAUN reporter

    I think that you should write a tiny documentation here on the repo, on how to use the library for both Java and FXML. I only found articles on your blog that weren't up to date anymore, hence my mistake. When we look at the code it's clear enough but I think that a documentation would be more efficient.

    Anyway, sorry again, good luck for the next updates :)

  6. Jens Deters repo owner

    Yes, I guess you're right. Will work on the documentation! Glad it's clarified now ;-)!

  7. Log in to comment