Cannot invoke "com.google.gson.JsonElement.isJsonNull()" because the return value of "com.google.gson.JsonObject.get(String)" is null
14:59 23 Oct 2020

I am trying to add a null check for my discord stats bot coded in java (with gson)

It's giving me this error: Cannot invoke "com.google.gson.JsonElement.isJsonNull()" because the return value of "com.google.gson.JsonObject.get(String)" is null

I have no idea why

Here is my code, hopefully you can help me resolve this issue.

public String getRank() {
        if (player.get("newPackageRank").isJsonNull()) {
            return "Non";
        } else {
            return player.get("newPackageRank").getAsString();
        }
    }

Any help is appreciated! thanks

java gson