Skip to content

Instantly share code, notes, and snippets.

@rhathaway
Created December 3, 2011 19:53
Show Gist options
  • Save rhathaway/1427961 to your computer and use it in GitHub Desktop.
Save rhathaway/1427961 to your computer and use it in GitHub Desktop.
wunderground in processing - not working
import com.francisli.processing.http.*;
HttpClient client;
void setup() {
client = new HttpClient(this, "api.wunderground.com");
client.GET("/api/[api_key]/conditions/q/CA/San_Francisco.json");
}
void responseReceived(HttpRequest request, HttpResponse response) {
//// check for HTTP 200 success code
if (response.statusCode == 200) {
println(response.getContentAsString());
JSONObject results = response.getContentAsJSONObject();
String locationInfo = results.get("full").stringValue();
String currentTime = results.get("observation_time").stringValue();
int tempF = results.get("temp_f").intValue();
int tempC = results.get("temp_c").intValue();
println(locationInfo);
println(currentTime);
println(tempF + "° F");
println(tempC + "° C");
}
}
void draw () {
}
@rhathaway
Copy link
Author

Returns NullPointerException:

Exception in thread "Animation Thread" java.lang.NullPointerException
at wunderground.responseReceived(wunderground.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.francisli.processing.http.HttpClient.pre(HttpClient.java:163)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:680)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment