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?
Starfield.java
public class Starfield extends ApplicationAdapter {
private static final float STAR_DENSITY = 0.01f;
ShapeRenderer shapeRenderer;
Array<Vector2> stars;
@Override
public void create() {
// Initialize a shapeRenderer
shapeRenderer = new ShapeRenderer();
// Call initStars
initStars(STAR_DENSITY);
}
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));
}
}
@Override
public void resize(int width, int height) {
shapeRenderer = new ShapeRenderer();
initStars(STAR_DENSITY);
}
@Override
public void render() {
// Make the night sky black
Gdx.gl.glClearColor(0, 0, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// Begin a shapeRenderer batch using ShapeType.Point
shapeRenderer.begin();
// 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
shapeRenderer.end();
}
@Override
public void dispose() {
// Dispose of our ShapeRenderer
shapeRenderer.dispose();
super.dispose();
}
}
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.
Error running Desktop: Unable to open debugger port (127.0.0.1:54999): java.net.SocketException "socket closed"
\$\endgroup\$ – ShivGames Mar 21 '17 at 12:11