1

If I start it for Desktop it runs pretty nice, but after the export for my Android it crashes right after I start the application.

So my question...:

What's wrong that it works for the Desktop but not for my Android?

public class Player implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = -7913517465400462738L;

Vector2 position;
private static final int col = 4;
private static final int row = 4;
private Animation animation;
private Texture playerTexture;
private TextureRegion[] frames;
private TextureRegion currentFrame;
private float stateTime;
private int x,y, deltaX, deltaY;



public Player(Vector2 position){
    this.position = position;
    playerTexture = new Texture(Gdx.files.internal("Charackter/charackter_sprite.png"));
    TextureRegion[][] temp = TextureRegion.split(playerTexture, playerTexture.getWidth() / col, playerTexture.getHeight() / row);
    frames = new TextureRegion[col* row];

    int index = 0;
    for(int i = 0; i < row; i++){
        for(int j = 0; j < col; j++){
            frames[index++] = temp[i][j];
        }
    }
    animation = new Animation(1, frames);
    stateTime = 0;
    currentFrame = animation.getKeyFrame(0);
    deltaX = Gdx.graphics.getWidth();
    deltaY = Gdx.graphics.getHeight();
}

public void update(){

    if(stateTime < 4){
    stateTime += Gdx.graphics.getDeltaTime();
    }
    else{
        stateTime = 0;
    }       

    if (Gdx.input.isTouched())
    {
        x = Gdx.input.getX();
        y = Gdx.input.getY();
        if(x < deltaX * 50 / 100 && y > deltaY * 35 / 100 && y < deltaY * 65 / 100){
            position.x -= 1;
            currentFrame = animation.getKeyFrame(4 + stateTime);
        }
        if(x > deltaX * 50 / 100 && y > deltaY * 35 / 100 && y < deltaY * 65 / 100){
            position.x += 1;
            currentFrame = animation.getKeyFrame(8 + stateTime);
        }
        if(y < deltaY * 35 / 100 ){
            position.y += 1;
            currentFrame = animation.getKeyFrame(12 + stateTime);
        }
        if(y > deltaY * 65 / 100 ){
            position.y -= 1;
            currentFrame = animation.getKeyFrame(0 + stateTime);
        }
    }
}


public Vector2 getPosition() {
    return position;
}
public void setPosition(Vector2 position) {
    this.position = position;
}
public TextureRegion getCurrentFrame() {
    return currentFrame;
}
}

.

public class PlayScreen implements Screen {

private SpriteBatch batch;
private Vector2 position;
private Game game;
private Player player;
private Texture bild;

public PlayScreen(Game game){
    this.game = game;
}

@Override
public void render(float delta) {       
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    player.update();
    batch.begin();
    batch.draw(player.getCurrentFrame(), player.getPosition().x, player.getPosition().y);
    batch.end();
}

@Override
public void resize(int width, int height) {
    // TODO Auto-generated method stub

}

@Override
public void show() {
    batch = new SpriteBatch();
    position = new Vector2(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
    player = new Player(position);
    bild = new Texture("spongebob.png");
}

@Override
public void hide() {
    // TODO Auto-generated method stub

}

@Override
public void pause() {
    // TODO Auto-generated method stub

}

@Override
public void resume() {
    // TODO Auto-generated method stub

}

@Override
public void dispose() {
    batch.dispose();

}

}

Logcat

11-25 11:25:20.990: D/dalvikvm(862): Trying to load lib /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb1caad50
11-25 11:25:21.040: D/dalvikvm(862): Added shared lib /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb1caad50
11-25 11:25:21.040: D/dalvikvm(862): No JNI_OnLoad found in /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb1caad50, skipping init
11-25 11:25:21.100: D/AndroidRuntime(862): Shutting down VM
11-25 11:25:21.100: W/dalvikvm(862): threadid=1: thread exiting with uncaught exception (group=0xb1a73d70)
11-25 11:25:21.110: E/AndroidRuntime(862): FATAL EXCEPTION: main
11-25 11:25:21.110: E/AndroidRuntime(862): Process: com.mygdx.game.android, PID: 862
11-25 11:25:21.110: E/AndroidRuntime(862): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mygdx.game.android/com.mygdx.game.android.AndroidLauncher}: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.ActivityThread.access$800(ActivityThread.java:138)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.os.Handler.dispatchMessage(Handler.java:102)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.os.Looper.loop(Looper.java:136)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.ActivityThread.main(ActivityThread.java:5026)
11-25 11:25:21.110: E/AndroidRuntime(862):  at java.lang.reflect.Method.invokeNative(Native Method)
11-25 11:25:21.110: E/AndroidRuntime(862):  at java.lang.reflect.Method.invoke(Method.java:515)
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
11-25 11:25:21.110: E/AndroidRuntime(862):  at dalvik.system.NativeStart.main(Native Method)
11-25 11:25:21.110: E/AndroidRuntime(862): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.badlogic.gdx.backends.android.AndroidGraphics.createGLSurfaceView(AndroidGraphics.java:122)
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:102)
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:95)
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.badlogic.gdx.backends.android.AndroidApplication.init(AndroidApplication.java:133)
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.badlogic.gdx.backends.android.AndroidApplication.initialize(AndroidApplication.java:99)
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.mygdx.game.android.AndroidLauncher.onCreate(AndroidLauncher.java:14)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.Activity.performCreate(Activity.java:5242)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
11-25 11:25:21.110: E/AndroidRuntime(862):  ... 11 more

I'm pretty new in Java so I hope it's the right part :x

Angel Angel
  • 19,670
  • 29
  • 79
  • 105
Fabi
  • 13
  • 3

2 Answers2

2

you use emulator?

libgdx android failed on launch

EDIT:

Opetion

I tell you what, because I found a similar question, I put down the logcat that question, and send this response, and the user is solved by changing the file,. TTF by. ttf and spent some time looking for the error, why was saying what I find confusing the log, however I have no windows, but the most striking difference I see between the two is that this line log 11-28 21:10:37.617: D/libEGL(613): Emulator without GPU support detected. Fallback to software renderer. that the log of this question is not listed. perhaps when the error is emulation or lack of OpenGL is more like the logcat or the first and when the file not found by the difference between uppercase and lowercase log you is more like the second, which says Emulator detected without GPU support. I hope I completely understand my English is not good

logcat this question; FATAL EXCEPTION : main - My app doesn't work on android devices anymore, but works on desktop

11-28 21:10:37.517: D/dalvikvm(613): Trying to load lib /data/data/com.premier.jeu.android/lib/libgdx.so 0x411998b0
11-28 21:10:37.527: D/dalvikvm(613): Added shared lib /data/data/com.premier.jeu.android/lib/libgdx.so 0x411998b0
11-28 21:10:37.527: D/dalvikvm(613): No JNI_OnLoad found in /data/data/com.premier.jeu.android/lib/libgdx.so 0x411998b0, skipping init
11-28 21:10:37.617: D/libEGL(613): Emulator without GPU support detected. Fallback to software renderer.
11-28 21:10:37.627: D/libEGL(613): loaded /system/lib/egl/libGLES_android.so
11-28 21:10:37.646: D/AndroidRuntime(613): Shutting down VM
11-28 21:10:37.646: W/dalvikvm(613): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
11-28 21:10:37.656: E/AndroidRuntime(613): FATAL EXCEPTION: main
11-28 21:10:37.656: E/AndroidRuntime(613): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.premier.jeu.android/com.premier.jeu.android.AndroidLauncher}: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0
11-28 21:10:37.656: E/AndroidRuntime(613):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
11-28 21:10:37.656: E/AndroidRuntime(613):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-28 21:10:37.656: E/AndroidRuntime(613):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-28 21:10:37.656: E/AndroidRuntime(613):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-28 21:10:37.656: E/AndroidRuntime(613):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 21:10:37.656: E/AndroidRuntime(613):  at android.os.Looper.loop(Looper.java:137)
11-28 21:10:37.656: E/AndroidRuntime(613):  at android.app.ActivityThread.main(ActivityThread.java:4745)
11-28 21:10:37.656: E/AndroidRuntime(613):  at java.lang.reflect.Method.invokeNative(Native Method)
11-28 21:10:37.656: E/AndroidRuntime(613):  at java.lang.reflect.Method.invoke(Method.java:511)
11-28 21:10:37.656: E/AndroidRuntime(613):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-28 21:10:37.656: E/AndroidRuntime(613):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-28 21:10:37.656: E/AndroidRuntime(613):  at dalvik.system.NativeStart.main(Native Method)
11-28 21:10:37.656: E/AndroidRuntime(613): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0
11-28 21:10:37.656: E/AndroidRuntime(613):  at com.badlogic.gdx.backends.android.AndroidGraphics.createGLSurfaceView(AndroidGraphics.java:122)
11-28 21:10:37.656: E/AndroidRuntime(613):  at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:102)
11-28 21:10:37.656: E/AndroidRuntime(613):  at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:95)
11-28 21:10:37.656: E/AndroidRuntime(613):  at com.badlogic.gdx.backends.android.AndroidApplication.init(AndroidApplication.java:133)
11-28 21:10:37.656: E/AndroidRuntime(613):  at com.badlogic.gdx.backends.android.AndroidApplication.initialize(AndroidApplication.java:99)
11-28 21:10:37.656: E/AndroidRuntime(613):  at com.premier.jeu.android.AndroidLauncher.onCreate(AndroidLauncher.java:16)
11-28 21:10:37.656: E/AndroidRuntime(613):  at android.app.Activity.performCreate(Activity.java:5008)
11-28 21:10:37.656: E/AndroidRuntime(613):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-28 21:10:37.656: E/AndroidRuntime(613):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-28 21:10:37.656: E/AndroidRuntime(613):  ... 11 more
11-28 21:10:39.476: I/Process(613): Sending signal. PID: 613 SIG: 9
Community
  • 1
  • 1
Angel Angel
  • 19,670
  • 29
  • 79
  • 105
  • well, i've just forgot to delete this part... i'll try it anyway, but I think the main problem is in the Player.class without this part everything works fine but i need this animation :/ – Fabi Nov 25 '14 at 08:47
  • @Fabi I should not have answered, but I did it if that was the mistake did not have to put the logcat, are now four persons in logcat ask you to try to help, and still do not have any negative feedback, and if you do not do to requests, not surprise me to close the question – Angel Angel Nov 25 '14 at 11:13
  • Oh sorry, my fault >.< i'm new here so it's a bit confusing i'll edit it – Fabi Nov 25 '14 at 11:18
  • you completely changed your answer D: – João Costa Nov 25 '14 at 11:34
  • 1
    @Opetion haha not previously had logcat – Angel Angel Nov 25 '14 at 11:35
  • yeah, tested it also on my handy because the emulator is so slow x.X I'll check the site right after the break :) – Fabi Nov 25 '14 at 11:37
  • @AngelAngel yeah, just noticed :) " Libgdx requires OpenGL ES 2.0 " your answer is probably right – João Costa Nov 25 '14 at 11:38
  • ah... i'm going to check it out, really tought it would say file not found or something – João Costa Nov 30 '14 at 00:12
  • @AngelAngel on my phone logcat gives the expected error " com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: fonts/UglyQua.ttf (Internal) " – João Costa Nov 30 '14 at 00:44
  • and same error with the emulator " 1232-1266/com.notequals.gow.android E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 182 Process: com.notequals.gow.android, PID: 1232 com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: fonts/UglyQua.ttf (Internal)" – João Costa Nov 30 '14 at 00:50
  • ok was able to reproduce the logcat error, it is due to the emulator not using the host gpu – João Costa Nov 30 '14 at 00:59
  • 1
    @Opetion do not know, that person had that error and fix well, one thing I can think of is that maybe, windows may not be able to shed casesensitve mistake, and whoever finds it is OpenGL and launches exception, as if anything ever goes wrong so mirare me that, if I was in windows :) P.S : if you want to delete any comments to not leave, very dirty this haha. – Angel Angel Nov 30 '14 at 01:22
  • 1
    @AngelAngel I have nothing to hide! not going to delete anything :P – João Costa Nov 30 '14 at 01:24
  • 1
    @Opetion your answer is complete now haha up vote :) logcat this question; try editing the title before but not leave me add FATAL EXCEPTION in the tile so you can find someone else with the same problem – Angel Angel Nov 30 '14 at 01:28
  • 1
    @AngelAngel hopefully it is! and with 100% less Wild guesses! :) thanks mate! ^^ I had already upvoted yours so there isn't more I can do. – João Costa Nov 30 '14 at 01:30
2

There has been some persons with exceptions where the logcat says:

GdxRuntimeException: Libgdx requires OpenGL ES 2.0   

This is due to your emulator not using your gpu for graphics and the best solution would be to use your phone to test your application but if for any reason you can't you can as @AngelAngel apply this solution: libgdx android failed on launch.
For some reason ( probably the opengl not glitching ) the solution to the following error might also help you

 com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: xxx.xxx

If you have this error only while experimenting in Android while it works on Windows it probably is because one of your assets doesn't exactly match the name you used on your code. Unix is case-sensative so image.jpg is different from Image.jpg . So check every asset you have to see if the names match!

Community
  • 1
  • 1
João Costa
  • 412
  • 4
  • 15
  • 2
    you are a life safer :D the charackter_sprite.png had to be charackter_sprite.PNG now it works, thanks a lot :) – Fabi Nov 25 '14 at 11:58
  • @Opetion your answer is right, my cuestion is. logcat that corresponds to the error, or had two errors, it seems weird that output log, not find a file, do not you think? – Angel Angel Nov 25 '14 at 12:27
  • @AngelAngel I believe Fabi had 2 errors. The first one which is related with what we see in the logcat ( which was provided later ). So your answer is correct, and in my opinion yours is the correct one for the question. And the 2nd error which I "wild guessed it" when there was no logcat. Wild guess because it's not the first time that happens to me since I've been developing in Windows and used to happen to me a lot when I wanted to test in Android :) This error is not in the logcat, because of the first error. – João Costa Nov 25 '14 at 13:46
  • 1
    @Opetion thanks for answering, believed it might please one of those crazy mistakes, the logcat shows one thing, which is given by a simpler, haha Fabi kill two birds with one bullet – Angel Angel Nov 25 '14 at 13:53
  • @AngelAngel luckily i answered before the logcat, or he would still have one problem ^^ – João Costa Nov 25 '14 at 13:54
  • 1
    Opetion if true, haha, yes, it is likely that Fabi, continue searching the error – Angel Angel Nov 25 '14 at 14:00
  • @Opetion chances are your solution, is the most correct in more cases than expected just answered a similar logcat, redirecting it to this response was very similar for the execepcion, and fix the error, perhaps should create a execepcion for that type of error because the departure from my point of view is somewhat confusing – Angel Angel Nov 29 '14 at 11:01
  • @AngelAngel I should probably edit the answer... But anyway in this case it was 2 different errors and the logcat is right. It just returns the first error it finds. In case of this question the error was because the emulator or maybe an old phone didn't support OpenGl ES 2.0. My answer fits after solving the 1st problem, I can't actually say the exact error that logcat would show, but it would be some kind of null pointer or file not found. People usually develop on Windows and don't detect these small errors or maybe don't know that on unix OS the filenames are case-sensative. – João Costa Nov 29 '14 at 15:16
  • Anyway I can't say that I agree that it could be created an exception for that, because either the file isn't really there FileNotFound, or the people just wrote the name wrong but anyway it is still a FileNotFound Exception. And with this kind of exception people just have to check if the file is there, and if it's there they have to check for case differences. – João Costa Nov 29 '14 at 15:19