Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I can't find a sulotions that solves my problem, I've tried pretty much every tip I can find, but with no luck.

Error :

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: assets/enemy.png

From code:

enemyImg = new Texture(Gdx.files.internal("assets/enemy.png"));

I've linked the asset file from android to desktop as I am supposed to. But still, no luck, the asset file in my desktop-project doesn't even update when I add my image to my android projects asset file.

Please help so I can get started :)

EDIT: Managed to load png now, but I have to manually put the picture in the desktop projects asset folder, so would still appriciate an answer on how to do it automaticly

share|improve this question
    
I've tried using enemyImg = new Texture(Gdx.files.internal("enemy.png")); aswell. –  iQue Jul 24 '13 at 16:24
    
Please read the full question before commenting :) –  iQue Jul 28 '13 at 22:31
add comment

1 Answer

up vote 4 down vote accepted

The "Couldn't load file" error message you see is caused by two possible things:

  • The path is invalid (probably this one)
  • The file format is not supported (rare, but possible what OS are you using? I have seen this with Macs)

First, check if the path is truly correct. Check this:

Gdx.app.log("AssetPath", Gdx.files.internal("assets/enemy.png").file().getAbsolutePath());

Make sure that path is valid, and if not correct it. (You can copy and paste it into a file browser and that should be good enough to check.

Second, check what settings/format you used to save the png file. I don't believe indexed png files are supported with libgdx. Try adjusting the settings you used to save the file and reload it. I have seen issues with MacOS X saving png files and not being able to load them in Windows/Android via libgdx.

If you are still having issues after all this, take a screen capture of your project folder, showing the asset files. Additionally, post the image file so someone might be able to identify the issue you are having.

Edit:

To answer the other part of your question I will assume you are using Eclipse.

Firstly, the asset folder in the desktop project isn't actually a folder. If you have a folder, delete/remove it. What you are instead doing is trying to create a symlink between the two projects to 'share' the same folder.

In your Desktop Project you should only have /lib and /src and some library references:

  1. Select the Desktop Project folder in Eclipse, Right-click > Build Path > Link Source...
  2. Click Browse..., navigate your file system and find the asset folder for the Android Project
  3. Set the folder name to be "assets" if it isn't already
  4. Press finish

Now when you build your desktop project, the assets folder in the android project will be treated as a source folder. All non-java files are copied into the /bin folder with your class files. When you change a file in the android asset folder, it will automatically get copied into the output folder.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.