0

So I have this weird problem. Application works within eclipse project, but when I export project to jar. file and run it, then I get IOexception when loading one of fxml files.

Here is the exception:

javafx.fxml.LoadException: 
com/root/tomaszm/Countdown.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at com.controller.tomaszm.WrittenNumbersController.initializeStoperAndCountdown(WrittenNumbersController.java:162)
    at com.controller.tomaszm.WrittenNumbersController.initialize(WrittenNumbersController.java:114)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at com.model.tomaszm.ChangeTheRoot.initialize(ChangeTheRoot.java:68)
    at com.controller.tomaszm.MainRootController.fireUpTheFeature(MainRootController.java:103)
    at com.controller.tomaszm.MainRootController.access$0(MainRootController.java:96)
    at com.controller.tomaszm.MainRootController$MouseClickListCell$1.handle(MainRootController.java:147)
    at com.controller.tomaszm.MainRootController$MouseClickListCell$1.handle(MainRootController.java:1)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
    at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
    at javafx.event.Event.fireEvent(Unknown Source)
    at javafx.scene.Scene$ClickGenerator.postProcess(Unknown Source)
    at javafx.scene.Scene$ClickGenerator.access$7900(Unknown Source)
    at javafx.scene.Scene$MouseHandler.process(Unknown Source)
    at javafx.scene.Scene$MouseHandler.access$1500(Unknown Source)
    at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
    at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
    at com.sun.glass.ui.View.notifyMouse(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
    at com.sun.glass.ui.win.WinApplication$$Lambda$38/1657033223.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
    at com.controller.tomaszm.CountdownController.initialize(CountdownController.java:63)
    ... 46 more

Tell me if You need some extra informations.

EDIT: Ive found out that this is a problem with loading the font file that is in source folder Files:

try {
            Font registerFont = Font.loadFont(getClass().getClassLoader().getResource("DS-DIGIT.ttf").openStream(), 30);
            labTime.setFont(registerFont);
        } catch (IOException e1) {
            Dialogs.create().title("Exception").masthead(null).message("Couldnt load the font fxml!").showException(e1);
            e1.printStackTrace();
        }

I just dont get it why this code work within the project and causes some weird errors when I make a jar file. Is there any way I can load this font properly? Btw. I remember in early stages of project that I have build jar file with font in it, and it was working with no problem.... Im counfused here.

enter image description here

2
  • Where is the DS-DIGIT.ttf located? Commented Mar 4, 2015 at 6:42
  • @ItachiUchiha I have included the image. Commented Mar 4, 2015 at 6:50

2 Answers 2

1

If you don't create the files within your code or copy them when you are building the project then it's clear that they are not in the build-folder.

So for example if you are using Ant for building your project then write a target that copies the ttf file to the same folder where your jar file will be created. As workaround you can copy it yourself to the same folder.

Sign up to request clarification or add additional context in comments.

2 Comments

so, is there a way to create this font file within a project that I will have everything within a jar later and no extra files needed?
Sorry didn't hat time to look again but it seems that you already solved it in your own way :)
0

So based on informtions from Juce I've been looking in the internet for solution how to include font into jar and then later use it. I've found this code:

InputStream istream = getClass().getResourceAsStream("/resources/SerpentineBolditalic.ttf");
Font myFont = Font.createFont(Font.TRUETYPE_FONT, istream);
myFont = myFont.deriveFont(36.0f);
lblNewLabel.setFont(myFont);

however some of the code like Font.TRUETYPE_FONT seems do depreciated with current Java edition. So I had to make some changes and now everything seems to be working:

InputStream is = this.getClass().getResourceAsStream("/DS-DIGIT.TTF");
Font uniFont = Font.loadFont(is, 30);
labTime.setFont(uniFont);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.