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 trial
om agrahari
Courses Plus Student 1,769 PointsIn Stormy app , writting the code for getting data using jsonObject , I am getting a fatal exception:okHttp dispatcher
when i am trying to get the data using currentweather object i am getting this error...... what should i do...please help asap
om agrahari
Courses Plus Student 1,769 PointsE/AndroidRuntime﹕ FATAL EXCEPTION: OkHttp Dispatcher Process: com.example.omi.stormy, PID: 21384 java.lang.NullPointerException: id == null at java.util.TimeZone.getTimeZone(TimeZone.java:349) at com.example.omi.stormy.CurrentWeather.getFormattedTime(CurrentWeather.java:53) at com.example.omi.stormy.MainActivity.getCurrentDetails(MainActivity.java:99) at com.example.omi.stormy.MainActivity.access$000(MainActivity.java:23) at com.example.omi.stormy.MainActivity$1.onResponse(MainActivity.java:56) at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:168) at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818)
1 Answer
Seth Kroger
56,416 PointsFrom the stack trace you're getting a null pointer exception when you try to look up the timezone in the getFormattedTime() method of CurrentWeather. It looks like you're pulling the timezone out of the JSON data but forgetting to store it in your CurrentWeather object.
om agrahari
Courses Plus Student 1,769 Pointsom agrahari
Courses Plus Student 1,769 Pointspackage com.example.omi.stormy;
import android.app.Activity; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.util.Log; import android.widget.Toast;
import com.squareup.okhttp.Call; import com.squareup.okhttp.Callback; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.Request; import com.squareup.okhttp.Response;
import org.json.JSONException; import org.json.JSONObject;
import java.io.IOException;
public class MainActivity extends Activity {
}