Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialms2030
2,973 PointsError: Non-static method 'setHumidity(double)' cannot be referenced from a static context.
Similar error for setTime, setIcon, etc.
private CurrentWeather getCurrentDetails(String jsonData) throws JSONException {
JSONObject forecast = new JSONObject(jsonData);
String timezone = forecast.getString("timezone");
Log.i(TAG, "From JSON: " + timezone);
JSONObject currently = forecast.getJSONObject("currently");
CurrentWeather currentWeather = new CurrentWeather();
CurrentWeather.setHumidity(currently.getDouble("humidity"));
CurrentWeather.setTime(currently.getLong("time"));
CurrentWeather.setIcon(currently.getString("icon"));
return new CurrentWeather();
}
public class CurrentWeather {
private String mIcon;
private long mTime;
private double mTemperature;
private double mHumidity;
private double mPrecipChance;
private String mSummary;
...
public void setHumidity(double humidity) {
mHumidity = humidity;
}
...
2 Answers
ms2030
2,973 PointsOK, I figured out my mistake. I was using the class CurrentWeather instead of the variable currentWeather. That static error sure didn't help any. Just a simple lowercase vs. uppercase oversight with big consequences.
CurrentWeather currentWeather = new CurrentWeather();
currentWeather.setHumidity(currently.getDouble("humidity"));
currentWeather.setTime(currently.getLong("time"));
currentWeather.setIcon(currently.getString("icon"));
currentWeather.setPrecipChance(currently.getDouble("precipProbability"));
currentWeather.setSummary(currently.getString("summary"));
currentWeather.setTemperature(currently.getDouble("temperature"));
Dyo Hendro
2,251 PointsWow thanks :)