0

The code looks something like this:

if (Gdx.app.getType() == ApplicationType.Android) path = "data/images/";
if (Gdx.app.getType() == ApplicationType.Desktop) path = "./bin/data/images";

(if i use "data/images/" for Desktop, i get a crash).

assetmanager.load(path + fileName), assetmanager.finishLoading() and later assetmanager.get(path + fileName) works perfectly in Eclipse and also on Android, but when i create a runnable .jar and launch it from console, i get Asset not loaded: ./bin/data/images/image.jpg. So for some reason it cannot access the data folder inside my .jar archive. How do i fix this?

Thanks!

  • Open your jar with 7zip or something like that and look, if the "data/images" folder is there. I guess there is something wrong with the "dependencies" and "order and export"- settings of the project. – Robert P Oct 27 '14 at 14:08
  • Yes, it is there. Also, when i add a folder named bin/data/images/ to the same folder that the .jar file is in, it will work. But i'd still prefer it to take the images from inside the .jar. – user2822797 Oct 27 '14 at 16:07
  • IT seems, like it does not want to use the internal `FileHanlde`... Just a try: Give the `load` method also the class (`Texture.class`) – Robert P Oct 28 '14 at 06:32
  • I'm sorry for not being clear, i didn't copy the code from my project. Actually i am using it like this: assetManager.load(images[i].path(), Texture.class) – user2822797 Oct 29 '14 at 01:30
  • And you are sure, that the path you get is right? Also: Why do you use "./bin/data/images" for Desktop and "data/images" for android? What is the crashe you are getting? – Robert P Oct 29 '14 at 06:35
  • The paths are correct, for example this one will work: `./bin/data/images/h.jpg`. When i use `data/images` for desktop, the crash looks something like this: `Asset not loaded: data/images/h.jpg`. I understand that the `./bin/` hack isn't the correct way to do things, but for some reason it's the only one that has been working for me. It's really weird.. – user2822797 Oct 29 '14 at 13:25
  • Did you use the libgdx setup ui to create the project or did you set dependencies etc. manually? If the adroid version is working and it is working in eclipse, i guaess something is worng with the dependencies... – Robert P Oct 29 '14 at 13:57
  • I used the app, but for some reason the desktop assets folder was not getting files from my android project. I deleted and replaced the desktop assets folder. It is working now, because all of the android's assets are availbable in there, too. Could there still be something wrong with that folder? Edit: I don't know if it's worth mentioning, but i am not using gradle. Instead i generated the needed Eclipse build files. – user2822797 Oct 29 '14 at 14:28
  • I guess the problem is that you are not using gradle. Therefore you need to add the dependencies manually. I am not sure if it is the same wit hthe new libgdx version, but before libgdx version 1.0 (i used this setup with Version 0.9) it worked like in this tutorial (http://obviam.net/index.php/getting-started-in-android-game-development-with-libgdx-create-a-working-prototype-in-a-day-tutorial-part-1/) **ATTENTION!** This tutorial is outdated, i am not sure, if it stil works this way, if not i suggest to create the project with setup ui+gradle and copy your source code. – Robert P Oct 29 '14 at 15:24
  • Well, it appers that when using `Gdx.files.internal("data/images/").list()` on a desktop app, it always returns an empty list. I guess `./bin/data/images/` was not affected by that. That is also why `"data/images/"` only worked on Android. The solution is to add every image manually, instead of looping through the folder. Thank you for your help! – user2822797 Oct 29 '14 at 19:10
  • So you solved this issue now? If fthats the case, please add the solution as an answer, it may help other people with the same problem. – Robert P Oct 30 '14 at 06:28

1 Answers1

0

Well, it appers that when using Gdx.files.internal("data/images/").list() on a desktop app, it always returns an empty list. I guess ./bin/data/images/ was not affected by that. That is also why "data/images/" only worked on Android. The solution is to add every image manually, instead of looping through the folder. Thank you for your help!