SparklingComet / java-mojang-api

Full Mojang API Wrapper
http://wiki.vg/Mojang_API
Apache License 2.0
45 stars 11 forks source link

Error on Mojang#connect() #3

Closed nea89o closed 2 years ago

nea89o commented 6 years ago

Upon trying to connect via Mojang#connect() I get a NullPointerException. I tracked this down to Mojang#connect() expecting https://status.mojang.com/check to return a Json OBJECT while it gives an array with the rough format

[
   {
     "service": "status"
   },
   {
     "service2": "status"
   }
]
SparklingComet commented 6 years ago

Apologies for my late reply. Can you please share the full stacktrace?

ineanto commented 6 years ago

I also get an NPE on Mojang#connect() i think that's the HashMap initialization ? image

nea89o commented 6 years ago

@SparklingComet your Mojang#connect() method expects a Jsonobject (via getJSONObject which returns null if the api returns an array) the following obj.forEach causes the NullPointerException. i currently dont have a stacktrace ready, but any call to Mojang#connect did this (accross various PCs)

SparklingComet commented 6 years ago

@Iddenn submitted a fix, please let me know whether the issue has been solved.

nea89o commented 6 years ago

import org.shanerx.mojang.Mojang;

public class Main {
    public static void main(String[] args) {
        Mojang mojang = new Mojang();
        mojang.connect();
    }
}

yields the following error

Exception in thread "main" java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to org.json.simple.JSONObject
    at org.shanerx.mojang.Mojang.getJSONObject(Mojang.java:329)
    at org.shanerx.mojang.Mojang.connect(Mojang.java:59)

which caused be the exact same problem as before: mojang.connect() expects https://status.mojang.com/check to return a JSONObject, but it returns a JSONArray

SparklingComet commented 6 years ago

Should be fixed, please report back if you can.

SparklingComet commented 2 years ago

Inactive issue, not relevant either way after #12 .