0
votes

I am trying to perform a basic JSON GET action in Processing. I have been using two open APIs that only need API key to authenticate. Have been receiving the following error message twice:

Couldn't create a reader for http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139&APPID=f77c39703fb6be71e2c5a96e58edc077

The error message I get is:

FATAL EXCEPTION: Animation Thread
Process: processing.test.jsonprocessingtutorial, PID: 26486
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.Reader.markSupported()' on a null object reference
    at processing.data.JSONTokener.<init>(Unknown Source)
    at processing.data.JSONObject.<init>(Unknown Source)
    at processing.core.PApplet.loadJSONObject(Unknown Source)
    at processing.test.jsonprocessingtutorial.JSONprocessingtutorial.loadData(JSONprocessingtutorial.java:46)
    at processing.test.jsonprocessingtutorial.JSONprocessingtutorial.setup(JSONprocessingtutorial.java:42)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PSurfaceNone.callDraw(Unknown Source)
    at processing.core.PSurfaceNone$AnimationThread.run(Unknown Source)

The API Key and GET call have been doublechecked.

The code in Processing is the following: 

String API_Key = "f77c39703fb6be71e2c5a96e58edc077";
String url = "http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139";
//specific url with coordinates for specific city 

void setup() {
  size(480, 360);
  loadData();
  }

void loadData(){
  JSONObject json = loadJSONObject(url+"&APPID="+API_Key);
  JSONObject windData = json.getJSONObject("wind");
  float speed = windData.getFloat("speed");
  println (speed); 
  }

The JSON response is the following: Trying to get the "Speed" out..

{
"coord": {
"lon": 139,
"lat": 35
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01n"
}
],
"base": "stations",
"main": {
"temp": 278.455,
"pressure": 1017.64,
"humidity": 100,
"temp_min": 278.455,
"temp_max": 278.455,
"sea_level": 1027.18,
"grnd_level": 1017.64
},
"wind": {
"speed": 11.86,
"deg": 272.003
},
"clouds": {
"all": 0
},
"dt": 1518460865,
"sys": {
"message": 0.0133,
"country": "JP",
"sunrise": 1518384771,
"sunset": 1518423842
},
"id": 1851632,
"name": "Shuzenji",
"cod": 200
}

PLEASE ADVICE! Thank you..

1

1 Answers

1
votes

I have found an answer to my question..

The solution is to use the "INTERNET Permission" under the Tab "Android - Sketch Permissions"..

Kind regards,

Niels