I have a libGdx app, and I am running it using android studio.

It closes immediately after starting it and I see no error report. Could anyone help?


public class Starfield extends ApplicationAdapter {

    private static final float STAR_DENSITY = 0.01f;
    ShapeRenderer shapeRenderer;
    Array<Vector2> stars;

    public void create() {
        // Initialize a shapeRenderer
        shapeRenderer = new ShapeRenderer();

        // Call initStars


    public void initStars(float density) {
        // Figure out how many stars to draw. You'll need the screen dimensions,  which you can get using
        // Gdx.graphics.getWidth() and Gdx.graphics.getHeight().
        int screenHeight = Gdx.graphics.getWidth();
        int screenWidth = Gdx.graphics.getHeight();

        // Create a new array of Vector2's to hold the star positions
        stars = new Array<Vector2>((int) (screenHeight * screenWidth * density));

        // Use java.util.Random to fill the array of star positions
        Random random = new Random();

        for (int i = 0; i < stars.size; i++) {

            int x = random.nextInt(screenWidth);
            int y = random.nextInt(screenHeight);

            stars.add(new Vector2(x, y));



public void resize(int width, int height) {
    shapeRenderer = new ShapeRenderer();

public void render() {
    // Make the night sky black
    Gdx.gl.glClearColor(0, 0, 1, 1);

    // Begin a shapeRenderer batch using ShapeType.Point

    // Loop through the star positions and use shapeRenderer to draw points
    for (Vector2 vec: stars) {

        shapeRenderer.point(vec.x, vec.y, 0);


    // End the shapeRenderer batch


    public void dispose() {
        // Dispose of our ShapeRenderer

Here is the gradle log

Run build   1s 241ms    
Run init scripts    33ms    
Configure settings  1ms 
Configure build 327ms   
Project :   326ms   
Resolve dependencies :classpath 200ms   
Resolve dependencies :android:classpath 0ms 
Calculate task graph    26ms    
Project :desktop    15ms    
Project :core   3ms 
Run tasks   824ms   
:core:compileJava   82ms    
Resolve dependencies :core:compileClasspath 5ms 
:core:processResources  3ms 
:core:classes   1ms 
:core:jar   16ms    
:desktop:compileJava    73ms    
Resolve dependencies :desktop:compileClasspath  14ms    
:desktop:processResources   2ms 
:desktop:classes    0ms 
:desktop:run    642ms   
Resolve dependencies :desktop:runtime   3ms 

EDIT: I got an error, dumb me, I did not see the console.

Exception in thread "LWJGL Application" java.lang.IllegalStateException:    autoShapeType must be true to use this method.
at com.badlogic.gdx.graphics.glutils.ShapeRenderer.begin(ShapeRenderer.java:198)
at gamedev.starfield.Starfield.render(Starfield.java:87)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)

Thanks, any help would be appreciated.

  • 1
    \$\begingroup\$ Can't you use a step-by-step debugger in Android Studio to spot where it crashes? \$\endgroup\$ – Vaillancourt Mar 21 '17 at 11:30
  • \$\begingroup\$ Just after the build! In the last line of the gradle build log. \$\endgroup\$ – ShivGames Mar 21 '17 at 12:06
  • \$\begingroup\$ if i try debugging, I get some error. Error running Desktop: Unable to open debugger port ( java.net.SocketException "socket closed" \$\endgroup\$ – ShivGames Mar 21 '17 at 12:11
  • \$\begingroup\$ Forget that, I put the stacktrace, I found an error. \$\endgroup\$ – ShivGames Mar 21 '17 at 12:18

You need to specify the ShapeType in the begin call on the ShapeRenderer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.