0

The information is good coming in. I debug it and get to the first writer and get a null exception, it is probably something very simple any comments and help would be appreciated.

public Json writeGame(Ship ship, Array<EnemyPlanes> enemyPlanesArray,
                          FinalEnemy finalEnemy,int Level, int Difficulty){
        Json json = new Json();
        json.writeValue("Level", Level);
        json.writeValue("Difficulty", Difficulty);
        json.writeObjectStart(Ship.class,null);
        json.writeField(ship.position.x, "X", float.class);
        json.writeField(ship.position.y, "Y", float.class);
        json.writeField(ship.hits, "Hits", int.class);
        json.writeField(ship.missiles_OnBoard, "Missiles", int.class);
        json.writeField(Constants.PLANE_MISSILES_ALLOWED, "Max Missiles", int.class);
        json.writeField(Constants.PLANE_BULLETS_ALLOWED, "Max Bullets", int.class);
        json.writeObjectEnd();

        return json;
    }

The stack trace is as follows:

Exception in thread "LWJGL Application" java.lang.NullPointerException at com.badlogic.gdx.utils.Json.writeValue(Json.java:376) at com.howlers.areoplanewars.game.Management.GameSave.writeGame(GameSave.java:85) at com.howlers.areoplanewars.game.Stages.GameStage.(GameStage.java:103) at com.howlers.areoplanewars.game.Screens.GameScreen.(GameScreen.java:23) at com.howlers.areoplanewars.game.AreoplaneWars.create(AreoplaneWars.java:50) at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147) at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)

This line is the problem, which means it is all a problem:

json.writeValue("Level", Level);
user1810577
  • 13
  • 1
  • 4
  • Can you post the full stack trace and highlight the line where it occurs? – BackSlash Sep 05 '16 at 21:08
  • 1
    I know for a fact that Level=1 and Difficulty=1 contain integers and all the other parameters have information in them. – user1810577 Sep 05 '16 at 21:59
  • I'm not sure if this really is a duplicate; [this is perhaps where the error lies](https://github.com/libgdx/libgdx/wiki/Reading-&-writing-JSON#serialization-methods)? – Ken Y-N Sep 06 '16 at 00:36
  • I solved this whole issue in Android Studio by using making a dependency on JSONSimple. I mean SIMPLE no mess, no fuss. Thanks to JSONSimple it simplified my code. – user1810577 Sep 07 '16 at 12:28

0 Answers0