Why do I get this file loading exception when trying to draw sprites with libgdx?

Posted by BluFire on Game Development See other posts from Game Development or by BluFire
Published on 2012-03-26T15:32:54Z Indexed on 2012/03/26 17:40 UTC
Read the original article Hit count: 402

Filed under:
|
|

I'm having trouble with the "Drawing Images" section on the libgdx tutorial. I set up the documents completely and I typed the code as follows:

public class Game implements ApplicationListener {
        public static final String LOG = Game.class.getSimpleName();
        private FPSLogger fpsLogger;
        private SpriteBatch batch;
        private Texture texture;
        private Sprite sprite;
        private TextureRegion region;

        //removed irrelevant code for this question...

        @Override
        public void render() {
                texture = new Texture(Gdx.files.internal("android.png"));
                region = new TextureRegion(texture, 20, 20, 50, 50);
                sprite = new Sprite(texture, 20, 20, 50, 50);
                sprite.setPosition(10, 10);
                sprite.setRotation(45);

                Gdx.gl.glClearColor(0f, 1f, 0f, 1f);
                Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
                batch.begin();
                batch.draw(texture,10,10);
                batch.draw(region,10,10);
                sprite.draw(batch);
                batch.end();

                // output the current FPS
                fpsLogger.log();
        }
}

I went through the tutorial on the website but when I run the code I get errors:

Exception in thread "LWJGL Application"
com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: android.png at
com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)  at
com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:55) at
com.badlogic.gdx.graphics.Texture.load(Texture.java:175)  at
com.badlogic.gdx.graphics.Texture.create(Texture.java:159)    at
com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)    at
com.badlogic.gdx.graphics.Texture.<init>(Texture.java:122)    at
com.game.Game.render(Game.java:46)    at
com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop (LwjglApplication.java:163) at
com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:113)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: android.png (Internal)     at
com.badlogic.gdx.files.FileHandle.read(FileHandle.java:108)   at
com.badlogic.gdx.files.FileHandle.length(FileHandle.java:364)     at
com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:156)  at
com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:134)  ... 8 more

I set the android.png in my assests folder in my android project linking it to the desktop one, I don't understand what I'm doing wrong. What is making these errors?

FIX. Weird ending.this was the plus where the sprite is suppose to look like. The top right corner of the next image should look like, the bottom left is what turned out in the code. I'm think it was because of the texture region but I'm not 100%. Can somebody explain why it is really warped? I thought the changes I made in the coding will just change position/rotation, rather then a change in the image.

enter image description here

© Game Development or respective owner

Related posts about android

Related posts about libgdx