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 trialsamuel zaffran
24,815 PointsDouble Errors
Hi, i have two issues, first when i launch my app, i have :
09-12 14:38:18.511 9822-9864/com.example.ideo.weather E/WeatherHome: exception caught org.json.JSONException: Value hourly of type java.lang.String cannot be converted to JSONObject at org.json.JSON.typeMismatch(JSON.java:111) at org.json.JSONObject.<init>(JSONObject.java:160) at org.json.JSONObject.<init>(JSONObject.java:173) at com.example.ideo.weather.UI.WeatherHome.getHourlyForecast(WeatherHome.java:202) at com.example.ideo.weather.UI.WeatherHome.parseForecastDetails(WeatherHome.java:165) at com.example.ideo.weather.UI.WeatherHome.access$300(WeatherHome.java:38) at com.example.ideo.weather.UI.WeatherHome$2.onResponse(WeatherHome.java:109) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:126) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)
Then, when i click on 7 days, i have :
09-12 14:40:01.041 9822-9822/com.example.ideo.weather E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.ideo.weather, PID: 9822 java.lang.NullPointerException: Attempt to invoke virtual method 'com.example.ideo.weather.weather.Day[] com.example.ideo.weather.weather.Forecast.getDailyForecast()' on a null object reference at com.example.ideo.weather.UI.WeatherHome.startDailyActivity(WeatherHome.java:260) at com.example.ideo.weather.UI.WeatherHome_ViewBinding$1.doClick(WeatherHome_ViewBinding.java:40) at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Don't understand, i search on the forum, found nothing. I posted my main code below, if you need anything else, tell me. Thank you !
1 Answer
Taylor Bryant
7,395 PointsThe methods that have the errors are getHourlyForecast and getDailyForecast
When you are retrieving the "daily" jsonobject from within the forecast object you need to use forecast.getJSONObject("daily") instead of JSONObject daily = new JSONObject("daily")
Same thing goes with the hourly one too.
samuel zaffran
24,815 PointsGreat, Thank's !!
samuel zaffran
24,815 Pointssamuel zaffran
24,815 Pointspublic class WeatherHome extends AppCompatActivity {
}