0

I am following this tutorial on libgdx. What i am trying to do is loading a texture from a copy of badlogic.jpg (copy is called wawa.jpg):

public class HelloWorld implements ApplicationListener {
    SpriteBatch spriteBatch;
    Texture texture;
    Texture watched_texture;
    BitmapFont font;
    Vector2 textPosition = new Vector2(100, 100);
    Vector2 textDirection = new Vector2(5, 3);

    @Override
    public void create () {
        font = new BitmapFont();
        font.setColor(Color.RED);
        texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
        watched_texture = new Texture(Gdx.files.internal("data/wawa.jpg"));
        spriteBatch = new SpriteBatch();
    }
...

What i get is the crash of application and "com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file data/wawa.jpg" in debug:

10-18 09:24:45.383: WARN/dalvikvm(330): threadid=9: thread exiting with uncaught exception (group=0x40015560)
10-18 09:24:45.502: ERROR/AndroidRuntime(330): FATAL EXCEPTION: GLThread 10
10-18 09:24:45.502: ERROR/AndroidRuntime(330): com.badlogic.gdx.utils.GdxRuntimeException: couldn't load file 'wawa.jpg'
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:135)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.graphics.Texture.(Texture.java:126)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.graphics.Texture.(Texture.java:104)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.test.myfirsttriangle.MyFirstTriangle.create(MyFirstTriangle.java:29)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceCreated(AndroidGraphics.java:284)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
10-18 09:24:45.502: ERROR/AndroidRuntime(330): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: data/wawa.jpg (Internal)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:64)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:132)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     ... 6 more
10-18 09:24:45.502: ERROR/AndroidRuntime(330): Caused by: java.io.FileNotFoundException: data/wawa.jpg
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.content.res.AssetManager.openAsset(Native Method)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.content.res.AssetManager.open(AssetManager.java:314)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.content.res.AssetManager.open(AssetManager.java:288)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:62)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     ... 7 more

Just can't figure out what's wrong.

Cubius
  • 1,294
  • 2
  • 15
  • 33
  • please put your solution as an answer and select it. That will make it easier for folks to find questions that need answers. See http://stackoverflow.com/faq#howtoask. (Its perfectly okay to answer your own questions. :) – P.T. Oct 27 '11 at 04:20

2 Answers2

3

I also had the same problem, but my mistake was a file name error.

The file was called gameScreenshot.PNG, and I had put in the string as "gameScreenshot.png".

In Windows it accepted the file name fine, but on android it didn't work, so I had to rename it to "gameScreenshot.PNG"

Trung
  • 31
  • 1
2

solved: i didn't put the new texture into the "assets" folder of android project

Cubius
  • 1,294
  • 2
  • 15
  • 33
  • One thing I ran into as well. If you put asset files in the folder via the file system, be sure to refresh the folder in eclipse. – agmcleod Dec 04 '12 at 19:49
  • This caught me out - I put it in the res/drawable-... folders instead (like I normally do for images on andorid) – jcw Jan 02 '14 at 23:23