0

My game runs correctly when I test the desktop version, but when I launch an android emulator and and try to run the game on the emulator the game closes and I get the logcat errors:

10-28 08:00:53.528: E/AndroidRuntime(1203): FATAL EXCEPTION: GLThread 84
10-28 08:00:53.528: E/AndroidRuntime(1203): Process: com.mkgame.game1.android, PID: 1203
10-28 08:00:53.528: E/AndroidRuntime(1203): com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: playButton2.png
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.graphics.Texture.load(Texture.java:130)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:121)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:92)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.MKgames.game1.screen.MainMenuScreen.<init>(MainMenuScreen.java:38)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.MKgames.Game1.create(Game1.java:29)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:236)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1512)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
10-28 08:00:53.528: E/AndroidRuntime(1203): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: playButton2.png (Internal)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:220)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
10-28 08:00:53.528: E/AndroidRuntime(1203):     ... 10 more
10-28 08:00:53.528: E/AndroidRuntime(1203): Caused by: java.io.FileNotFoundException: playButton2.png
10-28 08:00:53.528: E/AndroidRuntime(1203):     at android.content.res.AssetManager.openAsset(Native Method)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at android.content.res.AssetManager.open(AssetManager.java:316)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at android.content.res.AssetManager.open(AssetManager.java:290)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
10-28 08:00:53.528: E/AndroidRuntime(1203):     ... 12 more

I understand that the error migh be obvious that the file is not found, but it should be as it's location is fine and when i run it as a desktop app the file is fine (I copied all of my desktop assets into the android assets, they there are exactly the same). So what could the problem be?

Here is where i set the image:

Texture playButtonTxture = new Texture(Gdx.files.internal("playButton2.png"));
useruseruser
  • 73
  • 1
  • 6
  • possible duplicate of [Managing assets between desktop and device version in libgdx](http://stackoverflow.com/questions/9892964/managing-assets-between-desktop-and-device-version-in-libgdx) – ToYonos Oct 28 '14 at 15:45
  • possible duplicate of [FATAL EXCEPTION: GLThread 84: FileNotFoundException Android logcat errors](http://stackoverflow.com/questions/26607928/fatal-exception-glthread-84-filenotfoundexception-android-logcat-errors) – dawez Oct 28 '14 at 23:47

3 Answers3

0

You should take a look here and follow these instructions : https://github.com/libgdx/libgdx/wiki/Manual-project-setup#asset-folder-setup

The Android project has a subfolder named assets, which is created automatically. Files available to the Android application must be placed here. This is problematic, because these same files must be available to the desktop application. Rather than maintain two copies of all the files, the desktop project should be configured to find the assets in the Android project [...]

ToYonos
  • 16,469
  • 2
  • 54
  • 70
  • I have linked the androis assets for the desktop but i still get the same error – useruseruser Oct 28 '14 at 17:21
  • yeah i have tried that as well also, now that its linked it still works on desktop but it's still the android that throws up the same error – useruseruser Oct 28 '14 at 17:29
  • Did you take a look here ? http://stackoverflow.com/questions/9892964/managing-assets-between-desktop-and-device-version-in-libgdx – ToYonos Oct 28 '14 at 17:31
  • I believe the problem there was to do with linking the desktop to the android assets, but now that I have done that correctly I still get the error when running it on android so that is not really the same problem – useruseruser Oct 28 '14 at 17:37
  • 1
    The asset linking is done automatically. SO you put your "stuff" in android/assets and they are linked by the Desktop version as well. Try to create a new project and launch it without touching anything. The demo will be created with a texture image loaded. If that is working [desktop + android], then you have an issue in your current project. If the demo is not working then it's more complicated... – dawez Oct 28 '14 at 18:27
0

resources going to look for the asset folder, some from there if not inside any folder you want as picture 1,

enter image description here

and if within a folder picture 2 and so if in more folders without using the path absolute!

enter image description here

Edit:by the way your picture is a picture, good I mean that you can open with another program, not that this fence be corrupt

enter image description here Your mistake is that in the draft you have android as yourpicture.png is a windows shortcut or link to the photo, delete, and copy photo no link, if you do be sure to press the dragging I think windows control was also to copy

Angel Angel
  • 19,670
  • 29
  • 79
  • 105
  • sorry i don't understand what you mean – useruseruser Nov 13 '14 at 22:20
  • @useruseruser to see the files you have on the nombre.png directory, not the picture, it is a shortcut to the photo or link, try to delete and copy the photo again, if you use drag you to press the control key, or use copying and pasting – Angel Angel Nov 13 '14 at 22:27
0

Make sure you are putting your image in the correct place. Drag your image into the assets folder, then there should be a default data folder, drag your image into the data folder. Next in your code

Texture playButtonTxture = new Texture(Gdx.files.internal("playButton2.png"));

should now be

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

which is just pointing to the location of the image.

ilikeyoyo
  • 168
  • 4
  • 20