2011-10-15 5 views
0

Je suis le tutoriel this sur libgdx. Ce que je suis en train de faire est de charger une texture à partir d'une copie de badlogic.jpg (copie est appelée wawa.jpg):GdxRuntimeException: Impossible de charger le fichier

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(); 
    } 
... 

Ce que je reçois est le crash de l'application et « com.badlogic.gdx.utils .GdxRuntimeException: Impossible de charger les données de fichiers/wawa.jpg » dans 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 

Tout ne peut pas comprendre ce qui ne va pas.

+0

s'il vous plaît mettre votre solution en réponse et sélectionnez-le. Cela permettra aux gens de trouver plus facilement des questions qui ont besoin de réponses. Voir http://stackoverflow.com/faq#howtoask. (C'est tout à fait correct de répondre à vos propres questions. :) –

Répondre

2

résolu: Je ne l'ai pas mis la nouvelle texture dans le dossier « actif » du projet Android

+0

Une chose que j'ai rencontrée aussi. Si vous placez des fichiers d'actifs dans le dossier via le système de fichiers, veillez à actualiser le dossier dans Eclipse. – agmcleod

+0

Cela m'a piégé - je l'ai mis dans les dossiers res/drawable -... à la place (comme je le fais normalement pour les images sur andorid) – jcw

2

J'ai eu le même problème, mais mon erreur était une erreur de nom de fichier.

Le fichier s'appelait gameScreenshot.PNG, et j'avais mis dans la chaîne "gameScreenshot.png".

Dans Windows, il accepté le nom de fichier bien, mais sur Android, il ne fonctionne pas, donc je devais le renommer en « gameScreenshot.PNG »

Questions connexes