2
\$\begingroup\$

I am following a guide on creating a replica of Flappy Bird. - http://www.kilobolt.com/day-6-adding-graphics---welcome-to-the-necropolis.html

The step I am having trouble is loading the texture from the assets directory. There are the author's instructions on how to do this. enter image description here

And the code that he uses to actually load the texture

        texture = new Texture(Gdx.files.internal("data/texture.png"));

My file structure looks like this(I am using Android Studio 1.0 while the author is using eclipse) enter image description here

I had to manually create the data directory inside the assets folder. However when I try to run the application, I get these exceptions

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: data/texture.png
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: data\texture.png (Internal)

Does anyone know what the issue is? The texture.png is clearly inside the data directory of assets. I also made sure to clean the project right after copying the .png file into the data directory as the author mentioned.(so resources can be properly loaded). Is the issue just that were using two different IDES, so that different method calls have to be made?

\$\endgroup\$
5
  • \$\begingroup\$ in visual studio you have to change the properties of the image to "copy to output dire: copy always" and "build action: android asset", is there something similar in android studio ? also by any chance is the "/" a problem ? maybe it needs a "\" ? \$\endgroup\$
    – dimitris93
    Commented Jan 24, 2015 at 9:26
  • \$\begingroup\$ @Shiro It should be a forward slash. Windows accepts forward slashes for most paths since Windows 98, so don't think that's the actual issue . \$\endgroup\$
    – Mario
    Commented Jan 24, 2015 at 10:00
  • \$\begingroup\$ @Mario i thought that because in the error it says Couldn't load file: data/texture.png File not found: data\texture.png \$\endgroup\$
    – dimitris93
    Commented Jan 24, 2015 at 10:06
  • \$\begingroup\$ @Shiro That's probably due to the path conversion happening behind the scenes, however it might actually be some odd bug in com.badlogic.gdx as well (like backslashes being introduced somewhere but then handled the wrong way). \$\endgroup\$
    – Mario
    Commented Jan 24, 2015 at 10:08
  • 1
    \$\begingroup\$ Just something for you to try: Does the error also happen if you call the file _texture.png, i.e. avoiding the \t sequence in the path? \$\endgroup\$
    – Mario
    Commented Jan 24, 2015 at 10:08

1 Answer 1

1
\$\begingroup\$

On your run configuration make sure you have set your "Working directory" to your asset folder. Example:

Proper path

This only applies for the desktop run config.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .