Skip to main content
Update to answer how to automatically copy files.
Source Link
Jyro117
  • 321
  • 1
  • 5

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.

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.

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.

Source Link
Jyro117
  • 321
  • 1
  • 5

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.