Nifty: Error occured while loading asset

Hello,

I am currently going trough the nifty progress bar tutorial here: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:loading_screen

I am using the threaded way.

This is my preloader class. To test i am simply preloading 100 time a scene.

[java]/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.

    */

    package mygame.gameLogic;



    import java.util.concurrent.Callable;

    import java.util.logging.Level;

    import java.util.logging.Logger;

    import mygame.content.contentMap;

    import mygame.gameLogic.gameGui.guiLoading;



    /**

    *
  • @author zzuegg

    /

    public class GameCorePreLoader {

    private GameCore core;

    private guiLoading loadingScreen;

    private static final Logger logger = Logger.getLogger(GameCorePreLoader.class.getName());

    public GameCorePreLoader(GameCore core){

    this.core=core;

    this.loadingScreen=new guiLoading(this.core);

    core.getExec().submit(preLoadContent);

    }





    Callable<Void> preLoadContent = new Callable<Void>(){



    public Void call() throws Exception {

    for(int i=0;i<100;i++){

    contentMap tmp=new contentMap("MapDemo1",core);

    tmp.preLoad();

    loadingScreen.setProgress(100f/i,"MapDemo1"+i);

    logger.log(Level.INFO,"Loading map item "+i);



    }

    return null;

    }



    };

    }

    [/java]



    My guiLoading class, which is also the controller includes following. (I have modified the controller in the tutorial to hopefully support two progress bars)



    [java]

    /

  • To change this template, choose Tools | Templates
  • and open the template in the editor.

    */

    package mygame.gameLogic.gameGui;



    import com.jme3.niftygui.NiftyJmeDisplay;

    import de.lessvoid.nifty.Nifty;

    import de.lessvoid.nifty.controls.Controller;

    import de.lessvoid.nifty.elements.Element;

    import de.lessvoid.nifty.elements.render.TextRenderer;

    import de.lessvoid.nifty.input.NiftyInputEvent;

    import de.lessvoid.nifty.screen.Screen;

    import de.lessvoid.nifty.screen.ScreenController;

    import de.lessvoid.nifty.tools.SizeValue;

    import de.lessvoid.xml.xpp3.Attributes;

    import java.util.Properties;

    import mygame.gameLogic.GameCore;



    /**

    *
  • @author zzuegg

    */

    public class guiLoading implements ScreenController, Controller{

    private Element progressBarElement;

    private Element progressBarElement2;

    private TextRenderer textRenderer;

    private NiftyJmeDisplay niftyDisplay;

    private Nifty nifty;



    public guiLoading(GameCore core){

    this.niftyDisplay=new NiftyJmeDisplay(core.getAssetManager(),core.getInputManager(),core.getAudioManager(),core.getGuiViewPort());

    this.nifty=this.niftyDisplay.getNifty();

    this.nifty.fromXml("Interface/progressBar/progressBar.xml", "loadlevel",this);

    core.getGuiViewPort().addProcessor(niftyDisplay);

    }



    public void setProgress(final float progress, String loadingText) {

    final int MIN_WIDTH = 32;

    int pixelWidth = (int) (MIN_WIDTH + (progressBarElement.getParent().getWidth() - MIN_WIDTH) * progress);

    progressBarElement.setConstraintWidth(new SizeValue(pixelWidth + "px"));

    progressBarElement.getParent().layoutElements();



    textRenderer.setText(loadingText);

    }



    public void setProgress2(final float progress, String loadingText) {

    final int MIN_WIDTH = 32;

    int pixelWidth = (int) (MIN_WIDTH + (progressBarElement2.getParent().getWidth() - MIN_WIDTH) * progress);

    progressBarElement2.setConstraintWidth(new SizeValue(pixelWidth + "px"));

    progressBarElement2.getParent().layoutElements();



    textRenderer.setText(loadingText);

    }





    public void bind(Nifty nifty, Screen screen) {

    progressBarElement = nifty.getScreen("loadlevel").findElementByName("progressbar");

    progressBarElement = nifty.getScreen("loadlevel2").findElementByName("progressbar2");

    }



    public void onStartScreen() {



    }



    public void onEndScreen() {



    }



    public void bind(Nifty nifty, Screen screen, Element element, Properties parameter, Attributes controlDefinitionAttributes) {

    progressBarElement = element.findElementByName("progressbar");

    progressBarElement = element.findElementByName("progressbar2");

    }



    public void init(Properties parameter, Attributes controlDefinitionAttributes) {



    }



    public void onFocus(boolean getFocus) {



    }



    public boolean inputEvent(NiftyInputEvent inputEvent) {

    return (false);

    }



    }



    [/java]



    My Nifty progressBar.xml looks like this:

    [xml]

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

    <nifty>

    <useStyles filename="nifty-default-styles.xml" />

    <useControls filename="nifty-default-controls.xml" />



    <controlDefinition name = "loadingbar" controller = "mygame.gameLogic.gameGio.guiLoading">

    <image filename="Interface/progressBar/border.png" childLayout="absolute"

    imageMode="resize:15,2,15,15,15,2,15,2,15,2,15,15">

    <image id="progressbar" x="0" y="0" filename="Interface/progressBar/inner.png" width="32px" height="100%"

    imageMode="resize:15,2,15,15,15,2,15,2,15,2,15,15" />

    </image>

    </controlDefinition>



    <controlDefinition name = "loadingbar2" controller = "mygame.gameLogic.gameGio.guiLoading">

    <image filename="Interface/progressBar/border.png" childLayout="absolute"

    imageMode="resize:15,2,15,15,15,2,15,2,15,2,15,15">

    <image id="progressbar2" x="0" y="0" filename="Interface/progressBar/inner.png" width="32px" height="100%"

    imageMode="resize:15,2,15,15,15,2,15,2,15,2,15,15" />

    </image>

    </controlDefinition>





    <screen id="loadlevel" controller = "jme3test.TestLoadingScreen">

    <layer id="loadinglayer" childLayout="center" backgroundColor="#000000">

    <panel id = "loadingpanel" childLayout="vertical" align="center" valign="center" height="32px" width="400px">

    <control name="loadingbar" align="center" valign="center" width="400px" height="32px" />

    <control id="loadingtext" name="label" align="center"

    text=" "/>

    </panel>

    </layer>

    <layer id="loadinglayer2" childLayout="center" backgroundColor="#000000">

    <panel id = "loadingpanel2" childLayout="vertical" align="center" valign="center" height="32px" width="400px">

    <control name="loadingbar2" align="center" valign="center" width="400px" height="32px" />

    <control id="loadingtext2" name="label" align="center"

    text=" "/>

    </panel>

    </layer>

    </screen>





    </nifty>

    [/xml]



    I am getting following error on execution:

    [xml]

    com.jme3.asset.AssetLoadException: Error occured while loading asset "Interface/progressBar/border.png (Flipped)" usingAWTLoader

    at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:248)

    at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:293)

    at com.jme3.niftygui.RenderImageJme.<init>(RenderImageJme.java:56)

    at com.jme3.niftygui.RenderDeviceJme.createImage(RenderDeviceJme.java:117)

    at de.lessvoid.nifty.render.NiftyImageManager.getImage(NiftyImageManager.java:32)

    at de.lessvoid.nifty.render.NiftyRenderEngineImpl.createImage(NiftyRenderEngineImpl.java:161)

    at de.lessvoid.nifty.loaderv2.types.apply.ApplyRendererImage.apply(ApplyRendererImage.java:37)

    at de.lessvoid.nifty.elements.Element.initializeFromAttributes(Element.java:319)

    at de.lessvoid.nifty.loaderv2.types.ElementType.applyAttributes(ElementType.java:218)

    at de.lessvoid.nifty.loaderv2.types.ElementType.applyStandard(ElementType.java:172)

    at de.lessvoid.nifty.loaderv2.types.ElementType.create(ElementType.java:144)

    at de.lessvoid.nifty.loaderv2.types.ElementType.applyChildren(ElementType.java:251)

    at de.lessvoid.nifty.loaderv2.types.ElementType.applyStandard(ElementType.java:175)

    at de.lessvoid.nifty.loaderv2.types.ElementType.create(ElementType.java:144)

    at de.lessvoid.nifty.loaderv2.types.ElementType.applyChildren(ElementType.java:251)

    at de.lessvoid.nifty.loaderv2.types.ElementType.applyStandard(ElementType.java:175)

    at de.lessvoid.nifty.loaderv2.types.ElementType.create(ElementType.java:144)

    at de.lessvoid.nifty.loaderv2.types.ScreenType.create(ScreenType.java:80)

    at de.lessvoid.nifty.loaderv2.types.NiftyType.create(NiftyType.java:137)

    at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:521)

    at de.lessvoid.nifty.Nifty.fromXml(Nifty.java:431)

    at mygame.gameLogic.gameGui.guiLoading.<init>(guiLoading.java:34)

    at mygame.gameLogic.GameCorePreLoader.<init>(GameCorePreLoader.java:23)

    at mygame.gameLogic.GameCore.<init>(GameCore.java:39)

    at mygame.Main.simpleInitApp(Main.java:21)

    at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:230)

    at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)

    at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)

    at java.lang.Thread.run(Thread.java:722)

    [/xml]



    What can possibly cause the error?

You don’t have the images in your assets folder :roll:

Yes, they are in the correct folder., In this case Interface/progressBar/border.png and Interface/progressBar/inner.png

Try clean & build, obviously the images are not found, what shall I say…

also i’m noticing a few errors in there as well:

  • screen id=“loadlevel” controller = “jme3test.TestLoadingScreen” (should point to your controller)
  • progressBarElement = nifty.getScreen(“loadlevel2”).findElementByName(“progressbar2”); (you don’t have a screen with id loadlevel2)



    perhaps try get 1 progress bar working first, before trying with 2.

    And does the TestLoadingScreen1 example work for you?

No, if the asset is not found, following error gets thrown:

[java]

com.jme3.asset.AssetNotFoundException: Interface/progressBar/1.png (Flipped)

at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:239)

at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:293)

at com.jme3.niftygui.RenderImageJme.<init>(RenderImageJme.java:56)

at com.jme3.niftygui.RenderDeviceJme.createImage(RenderDeviceJme.java:117)

[/java]

wezrule said:
also i'm noticing a few errors in there as well:
- screen id="loadlevel" controller = "jme3test.TestLoadingScreen" (should point to your controller)
- progressBarElement = nifty.getScreen("loadlevel2").findElementByName("progressbar2"); (you don't have a screen with id loadlevel2)

perhaps try get 1 progress bar working first, before trying with 2.


Of course this would be the better way. But i am getting the same error with only one progress bar

So can you open the images in an image editor? Maybe save them in another format.

Thank you very much (again), it was indeed a problem with the picture files. Opening the file with the Editor and resaving it solved the problem

Where can I get these images? inner1.png and border.png?

Not in test data not on the wiki.

https://jmonkeyengine.github.io/wiki/jme3/advanced/loading_screen.html