1. Nimm jetzt an unserem Uhans - 3. ADVENT - Gewinnspiel teil - Alle Informationen findest Du hier!

Libgdx - GdxRuntimeException Couldn't load file...

Dieses Thema im Forum "Android App Entwicklung" wurde erstellt von emyaz, 18.03.2012.

  1. emyaz, 18.03.2012 #1
    emyaz

    emyaz Threadstarter Gast

    Hallo,
    also ich habe eine App geschrieben (meine erste :D), die die Neigung des Handys mit Hilfe der Beschleunigungssensoren anzeigen soll und außerdem sollen noch 2 Bilder angezeigt werden. Ich benutze Libgdx als Framework.
    Das Problem ist jetzt, dass die App immer abstürzt wenn man sie öffnet. Ich weiß, dass es beim Öffnen der Bilder passiert, jedoch habe ich keine Ahnung wie ich das Problem lösen kann.

    Hier sind die Debug-Ausgaben...
    Code:
    03-18 13:26:09.515: D/dalvikvm(312): Trying to load lib /data/data/com.cool.test.android/lib/libgdx.so 0x40514340
    03-18 13:26:09.525: D/dalvikvm(312): Added shared lib /data/data/com.cool.test.android/lib/libgdx.so 0x40514340
    03-18 13:26:09.525: D/dalvikvm(312): No JNI_OnLoad found in /data/data/com.cool.test.android/lib/libgdx.so 0x40514340, skipping init
    03-18 13:26:10.915: I/AndroidInput(312): sensor listener setup
    03-18 13:26:10.925: D/libEGL(312): egl.cfg not found, using default config
    03-18 13:26:10.935: D/libEGL(312): loaded /system/lib/egl/libGLES_android.so
    03-18 13:26:11.135: I/AndroidGraphics(312): OGL renderer: Android PixelFlinger 1.4
    03-18 13:26:11.135: I/AndroidGraphics(312): OGL vendor: Android
    03-18 13:26:11.135: I/AndroidGraphics(312): OGL version: OpenGL ES-CM 1.0
    03-18 13:26:11.135: I/AndroidGraphics(312): OGL extensions: GL_OES_byte_coordinates GL_OES_fixed_point GL_OES_single_precision GL_OES_read_format GL_OES_compressed_paletted_texture GL_OES_draw_texture GL_OES_matrix_get GL_OES_query_matrix GL_OES_EGL_image GL_OES_compressed_ETC1_RGB8_texture GL_ARB_texture_compression GL_ARB_texture_non_power_of_two GL_ANDROID_user_clip_plane GL_ANDROID_vertex_buffer_object GL_ANDROID_generate_mipmap 
    03-18 13:26:11.135: I/AndroidGraphics(312): framebuffer: (5, 6, 5, 0)
    03-18 13:26:11.135: I/AndroidGraphics(312): depthbuffer: (16)
    03-18 13:26:11.135: I/AndroidGraphics(312): stencilbuffer: (0)
    03-18 13:26:11.135: I/AndroidGraphics(312): samples: (0)
    03-18 13:26:11.145: I/AndroidGraphics(312): coverage sampling: (false)
    03-18 13:26:11.225: I/AndroidGraphics(312): Managed meshes/app: { }
    03-18 13:26:11.225: I/AndroidGraphics(312): Managed textures/app: { }
    03-18 13:26:11.275: I/AndroidGraphics(312): Managed shaders/app: { }
    03-18 13:26:11.275: I/AndroidGraphics(312): Managed buffers/app: { }
    03-18 13:26:11.635: D/dalvikvm(312): GC_CONCURRENT freed 352K, 51% free 2864K/5831K, external 716K/1038K, paused 4ms+5ms
    03-18 13:26:11.695: W/dalvikvm(312): threadid=10: thread exiting with uncaught exception (group=0x40015560)
    03-18 13:26:11.705: E/AndroidRuntime(312): FATAL EXCEPTION: GLThread
    03-18 13:26:11.705: E/AndroidRuntime(312): com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: assets/ball.png
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.graphics.Texture.load(Texture.java:175)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.graphics.Texture.create(Texture.java:159)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:122)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.cool.test.CoolTestExample.create(CoolTestExample.java:35)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:292)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.backends.android.surfaceview.GLSurfaceViewCupcake$GLThread.guardedRun(GLSurfaceViewCupcake.java:708)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.backends.android.surfaceview.GLSurfaceViewCupcake$GLThread.run(GLSurfaceViewCupcake.java:646)
    03-18 13:26:11.705: E/AndroidRuntime(312): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: assets/ball.png (Internal)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:66)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.files.FileHandle.length(FileHandle.java:542)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.backends.android.AndroidFileHandle.length(AndroidFileHandle.java:148)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:202)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
    03-18 13:26:11.705: E/AndroidRuntime(312):     ... 9 more
    03-18 13:26:11.705: E/AndroidRuntime(312): Caused by: java.io.FileNotFoundException: assets/ball.png
    03-18 13:26:11.705: E/AndroidRuntime(312):     at android.content.res.AssetManager.openAsset(Native Method)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at android.content.res.AssetManager.open(AssetManager.java:314)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at android.content.res.AssetManager.open(AssetManager.java:288)
    03-18 13:26:11.705: E/AndroidRuntime(312):     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:64)
    03-18 13:26:11.705: E/AndroidRuntime(312):     ... 13 more
    03-18 13:26:11.725: I/AndroidInput(312): sensor listener tear down
    03-18 13:26:11.725: I/AndroidGraphics(312): Managed meshes/app: { }
    03-18 13:26:11.725: I/AndroidGraphics(312): Managed textures/app: { }
    03-18 13:26:11.725: I/AndroidGraphics(312): Managed shaders/app: { }
    03-18 13:26:11.725: I/AndroidGraphics(312): Managed buffers/app: { }
    Das Bild ist aber da. Wieso geht es nicht??? :confused:

    Hier ist noch der Code
    Code:
    package com.cool.test;
    
    import com.badlogic.gdx.ApplicationListener;
    import com.badlogic.gdx.Gdx;
    import com.badlogic.gdx.graphics.Color;
    import com.badlogic.gdx.graphics.GL10;
    import com.badlogic.gdx.graphics.Texture;
    import com.badlogic.gdx.graphics.g2d.BitmapFont;
    import com.badlogic.gdx.graphics.g2d.SpriteBatch;
    
    public class CoolTestExample implements ApplicationListener 
    {
        SpriteBatch spriteBatch;
        BitmapFont font;
        Texture ball;
        Texture ball2;
        
        boolean show = true;
        
        float acceX = 0; 
        float acceY = 0;
        
        int ball2YPosition = 480; 
        
        String acceXString;
        String acceYString;
        
        
        @Override
        public void create()
        {
            font = new BitmapFont();
            font.setColor(Color.BLUE);
            spriteBatch = new SpriteBatch();
            ball = new Texture(Gdx.files.internal("assets/ball.png"));
            ball2 = new Texture(Gdx.files.internal("assets/ball.png"));
        }
    
        @Override
        public void dispose() 
        {
            
        }
        
        @Override
        public void pause() 
        {
            
        }
    
        @Override
        public void render() 
        {
            if(show)
            {
                Gdx.gl.glClearColor(1, 1, 1, 1);
                Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
                
                acceX = Gdx.input.getAccelerometerX();
                acceY = Gdx.input.getAccelerometerY();
                
                spriteBatch.begin();
                spriteBatch.setColor(Color.WHITE);
                
                acceXString = acceX + "";
                acceYString = acceY + "";
                
                ball2YPosition--;
    
                font.draw(spriteBatch, "X", 235, 470);
                font.draw(spriteBatch, "Y", 235, 450);
                
                font.draw(spriteBatch, acceXString, 250, 470);
                font.draw(spriteBatch, acceYString, 250, 450);
                
                spriteBatch.draw(ball, acceX, acceX, ball.getWidth(), ball.getHeight());
                spriteBatch.draw(ball2, ((Gdx.graphics.getWidth()/2)-(ball2.getWidth()/2)), ball2YPosition, ball2.getWidth(), ball2.getHeight());
                
                spriteBatch.end();
            }
            
            if(Gdx.input.isTouched())
            {
                show = false;
                Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
            }
        }
    
        @Override
        public void resize(int arg0, int arg1) 
        {
        }
    
        @Override
        public void resume() 
        {
        }
    }
    
    Da ich noch keine Erfahrung in Java habe ist der Code ein bisschen schlampig geschrieben, ich weiß :blushing:...

    Ich bedanke mich im Vorraus...
    emyaz
     
    Zuletzt von einem Moderator bearbeitet: 18.03.2012
  2. emyaz, 18.03.2012 #2
    emyaz

    emyaz Threadstarter Gast

    Ok habe es gelöst...
    Der Pfad zu dem Bild ist nur "ball.png" und nicht "assets/ball.png", obwohl es sich im assets Ordner befindet. Naja egal... hauptsache es funktioniert.
     
    Zuletzt von einem Moderator bearbeitet: 18.03.2012

Diese Seite empfehlen