I'm learning java recently and when I wanted to parse the data from a weather website, I got this error and I still can't figure it out, can anybody tell why I got this error: java.lang.NullPointerException ?
public class main {
public static void main(String []args) {
try {
URL url = new URL("http://api.worldweatheronline.com/premium/v1/past-weather.ashx?key=caa2f68a7b2b43a09c115021171404&format=json&q=atlanta&date=2015-07-20&tp=24");
InputStream is = url.openStream();
JsonReader rdr = Json.createReader(is);
JsonObject obj = rdr.readObject();
JsonArray data = obj.getJsonArray("weather");
JsonObject objectOfData = data.getJsonObject(0);
System.out.println(objectOfData.getString("date"));
} catch (Exception ex){
System.out.println(ex);
}
}
}
Here is the data parsed from Postman:
Here is the trace log:
Here is the picture of line 19