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 trialSarvesh Tandon
1,142 PointsI am getting data config error please help
```05-25 20:49:53.955 19189-19214/com.sarveshtandon.www.stormy D/OpenGLRenderer: Swap behavior 1 05-25 20:49:53.956 19189-19214/com.sarveshtandon.www.stormy W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 05-25 20:49:53.956 19189-19214/com.sarveshtandon.www.stormy D/OpenGLRenderer: Swap behavior 0 05-25 20:49:53.986 19189-19214/com.sarveshtandon.www.stormy D/EGL_emulation: eglCreateContext: 0xa08050c0: maj 2 min 0 rcv 2 05-25 20:49:54.012 19189-19214/com.sarveshtandon.www.stormy D/EGL_emulation: eglMakeCurrent: 0xa08050c0: ver 2 0 (tinfo 0xa0803330) 05-25 20:49:54.091 19189-19214/com.sarveshtandon.www.stormy W/android.hardware.graphics.mapper@2.0::Mapper: getService: found null hwbinder interface 05-25 20:49:54.093 19189-19214/com.sarveshtandon.www.stormy I/vndksupport: sphal namespace is not configured for this process. Loading /system/lib/hw/gralloc.ranchu.so from the current namespace instead. 05-25 20:49:54.142 19189-19214/com.sarveshtandon.www.stormy D/EGL_emulation: eglMakeCurrent: 0xa08050c0: ver 2 0 (tinfo 0xa0803330) 05-25 20:49:55.737 19189-19189/com.sarveshtandon.www.stormy W/zygote: Could not load plugin: dlopen failed: dlopen failed: library "libopenjdkjvmti.so" not found 05-25 20:49:55.737 19189-19189/com.sarveshtandon.www.stormy E/ActivityThread: Attaching agent failed: /data/data/com.sarveshtandon.www.stormy/libperfa_x86.so=/data/local/tmp/perfd/agent.config
```package com.sarveshtandon.www.stormy;
import android.nfc.Tag;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
private CurrentWeather currentWeather;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String apiKey = "e9267719c11970d4e600f3cd50f7e94c";
double latitude = 37.8267;
double longtude = -122.4233;
String forecastURL= "https://api.darksky.net/forecast/" + apiKey + "/" + latitude + "," + longtude;
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(forecastURL).build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
try {
String JSONData = response.body().string();
Log.v(TAG, JSONData);
if(response.isSuccessful()){
currentWeather = getCurrentDetails(JSONData);
}
else{
alertUserAboutTheError();
}
} catch (IOException e) {
Log.e(TAG, "IOException Caught:" ,e);
} catch (JSONException e){
Log.e(TAG, "JSONException caught:",e);
}
}
});
}
private CurrentWeather getCurrentDetails(String data) throws JSONException {
JSONObject forecast = new JSONObject(data);
String timezone = forecast.getString("timezone");
Log.i(TAG, "From JSON:"+timezone);
JSONObject currently = forecast.getJSONObject("currently");
currentWeather.setTemperature(currently.getDouble("temperature"));
currentWeather.setTime(currently.getLong("time"));
currentWeather.setHumidity(currently.getDouble("humidity"));
currentWeather.setLocationLabel("Alcataraz Island, CA");
currentWeather.setIcon(currently.getString("icon"));
currentWeather.setPrecipChance(currently.getDouble("precipProbability"));
currentWeather.setSummary(currently.getString("summary"));
Log.i(TAG, currentWeather.getFormattedTime(timezone));
return currentWeather;
}
private void alertUserAboutTheError() {
AlertDialogFragment dialog = new AlertDialogFragment();
dialog.show(getFragmentManager(), "error_dialog");
}
}
1 Answer
Jonathan Grieve
Treehouse Moderator 91,253 PointsI believe you forgot to instantiate your CurrentWeather object, that goes in the CurrentWeather method `
CurrentWeather currentWeather = new CurrentWeather();
Put it below the getJSONObject line.
Sarvesh Tandon
1,142 PointsSarvesh Tandon
1,142 Points05-25 20:49:55.737 19189-19189/com.sarveshtandon.www.stormy W/zygote: Could not load plugin: dlopen failed: dlopen failed: library "libopenjdkjvmti.so" not found 05-25 20:49:55.737 19189-19189/com.sarveshtandon.www.stormy E/ActivityThread: Attaching agent failed: /data/data/com.sarveshtandon.www.stormy/libperfa_x86.so=/data/local/tmp/perfd/agent.config
What does this mean ? How do I fix it?