Priyank
Priyank

Reputation: 83

Getting an error while trying to code with libGDX


I am trying to develop a new game using libGDX.
Since i am a beginner to libGDX firstly i am trying to display an image on the screen. I've followed the tutorial and wrote the code accordingly,but i am getting an error as "Unfortunately, has been stopped".
My error logcat is:-

05-28 09:20:10.740: E/memtrack(581): Couldn't load memtrack module (No such file or directory)
05-28 09:20:10.740: E/android.os.Debug(581): failed to load memtrack module: -2
05-28 09:20:13.560: E/cutils-trace(581): Error opening trace file: No such file or directory (2)
05-28 09:20:13.580: E/cutils-trace(1707): Error opening trace file: No such file or directory (2)
05-28 09:20:19.680: E/EmojiFactory_jni(581): Failed to load libemoji.so: dlopen failed: library "libemoji.so" not found
05-28 09:41:43.130: E/cutils-trace(1745): Error opening trace file: No such file or directory (2)
05-28 09:41:43.170: E/memtrack(1745): Couldn't load memtrack module (No such file or directory)
05-28 09:41:43.170: E/android.os.Debug(1745): failed to load memtrack module: -2


The code for configuration is:-

package com.mygdx.game.android;

import android.os.Bundle;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;


public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();

        initialize(new MyDemo(), config);
    }
}


The code of MyDemo.java:-

package com.mygdx.game.android;
import javax.microedition.khronos.opengles.GL10;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import android.app.Application;


public class MyDemo
implements ApplicationListener{
private OrthographicCamera camera;
private Texture texture;
private TextureRegion tr;
private Sprite s;
private SpriteBatch sb;
    public MyDemo() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void create() {
        // TODO Auto-generated method stub
        float w=Gdx.graphics.getWidth();
        float h=Gdx.graphics.getHeight();
        camera=new OrthographicCamera(1,h/w);
        sb=new SpriteBatch();
        texture=new Texture(Gdx.files.internal(("data/badlogic.jpg")));
        texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        s=new Sprite(texture);
        s.setSize(0.9f, 0.9f*s.getHeight()/s.getWidth());
        s.setOrigin(s.getWidth()/2, s.getHeight()/2);
        s.setPosition(-s.getWidth()/2,-s.getHeight()/2);
    }

    @Override
    public void dispose() {
        // TODO Auto-generated method stub
        sb.dispose();
        texture.dispose();
    }

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

    }

    @Override
    public void render() {
        // TODO Auto-generated method stub
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        sb.setProjectionMatrix(camera.combined);
        sb.begin();
        s.draw(sb);
        sb.end();
    }

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

    }

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

    }

}


I've put badlogic.jpg file in assets folder.
Please help me!
Thanks in advance.

Upvotes: 0

Views: 415

Answers (1)

Joozey
Joozey

Reputation: 238

These two imports don't make sense:

import javax.microedition.khronos.opengles.GL10;
import android.app.Application;

If they are valid imports in your core project, you have probably added libraries that generate the error you have. You should be able to do with only this import:

import com.badlogic.gdx.graphics.GL20;

Upvotes: 1

Related Questions