JUnit error in LibGDX

Answered

Hi, I'm fairly new to using LibGDX/Gradle and I've made a JUnit test to try and test one of my classes (which includes a function to draw a box on the screen, therefore I need to include a ShapeRenderer). When I am trying to test a function using JUnit (which is unrelated to the box-drawing function), it comes up with this error:

java.lang.NullPointerException
at com.badlogic.gdx.graphics.glutils.ShaderProgram.loadShader(ShaderProgram.java:209)
at com.badlogic.gdx.graphics.glutils.ShaderProgram.compileShaders(ShaderProgram.java:188)
at com.badlogic.gdx.graphics.glutils.ShaderProgram.<init>(ShaderProgram.java:171)
at com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20.createDefaultShader(ImmediateModeRenderer20.java:233)
at com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20.<init>(ImmediateModeRenderer20.java:56)
at com.badlogic.gdx.graphics.glutils.ShapeRenderer.<init>(ShapeRenderer.java:116)
at com.badlogic.gdx.graphics.glutils.ShapeRenderer.<init>(ShapeRenderer.java:111)
at com.badlogic.gdx.graphics.glutils.ShapeRenderer.<init>(ShapeRenderer.java:107)
at com.kroy.entities.Entity.<init>(Entity.java:22)
at EntityTest.testInRangeBoundary(EntityTest.java:11) <19 internal calls>
at java.base/java.util.ArrayList.forEach(ArrayList.java:1540) <9 internal calls>
at java.base/java.util.ArrayList.forEach(ArrayList.java:1540) <21 internal calls>

(Entity is the class, EntityTest and testInRangeBoundary are the JUnit bits)

Any idea what this error is and how I could solve it?

0
5 comments

Does the test run outside of IntelliJ IDEA using the command line `gradle test`?

It looks like some configuration issue not specific to the IDE. In order to get help you should probably share the project to illustrate the issue: https://stackoverflow.com/help/mcve .

0
Avatar
Permanently deleted user

Hi, I'm not sure how to run the test outside of IntelliJ IDEA.

Here is my Entity class, and the basics of my JUnit test:

public class Entity{
int range;
public Point position;
ShapeRenderer shape = new ShapeRenderer();

public Entity(int range, Point position){
this.range = range;
this.position = position;
}


//The part I'm testing
public boolean inRange(Entity target){
if(abs(target.position.x - this.position.x) < this.range &&
abs(target.position.y - this.position.y) < this.range){
return true;
}
return false;
}


public void drawBox(ArrayList<Entity> target, OrthographicCamera camera, Sprite sprite) {
//Draws a box (and needs the camera to do so)
}
}
 import com.kroy.entities.Entity;
import com.kroy.game.Point;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;

class EntityTest {

@Test
public void testInRangeBoundary() {
Entity e = new Entity(5, new Point(5,5));
Assertions.assertTrue(e.inRange(new Entity(0,new Point(9,0))));
}
}
0
Avatar
Permanently deleted user

I'm still not really sure how to do that, I get this error when I try: Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.

I agree that it's probably not related to IntelliJ but I still don't know how to solve it, any help would be much appreciated.

0

You need to configure JDK properly as described in the error message.

For the help with IntelliJ IDEA configuration you need to share the project using some file sharing service or GitHub. See https://stackoverflow.com/help/mcve for the details what exactly to share.

0

Please sign in to leave a comment.