Screen Is Empty After Fetching Weather Information
tonespy opened this issue · comments
Okay. So, I started with the tutorial and everything has been going on fine not until I got to chapter 10 trying to implement the Asyn.
doAsync {
val result = RequestForecastCommand("94043").execute()
Log.e(javaClass.simpleName, result.toString()) <-- It doesn't get to this place at all
uiThread() {
Log.e(TAG, "I am here")
Log.e(javaClass.simpleName, result.toString())
forcast_list.adapter = ForcastListAdapter(result)
}
}
Then, I debugged further and checked the ForecastRequest.kt
file
class ForecastRequest(val zipCode: String) {
companion object {
private val APP_ID = "15646a06818f61f7b8d7823ca833e1ce"
private val URL = "http://api.openweathermap.org/data/2.5/" +
"forecast/daily?mode=json&units=metric&cnt=7"
private val COMPLETE_URL = "$URL&APPID=$APP_ID&q="
}
fun execute(): ForecastResult {
val forcastJsonStr = URL(COMPLETE_URL + zipCode).readText()
Log.e(javaClass.simpleName, forcastJsonStr)<-- This printed out a result
return Gson().fromJson(forcastJsonStr, ForecastResult::class.java)
}
}
I don't know why it's not throwing any error or any bug though. And should it be a Gson conversion error, at least I'm supposed to get an error right?
The API may have changed, I'll take a look. Thanks!
Regarding the exception not being thrown, you have some more info here: Kotlin/anko#182
Okay. Now I get it. But, I've not experienced the issue few hours after I posted the question. Probably something was going on. Because, the data was logged correctlly and the JSON object was in correlation with the POJO objects. Looking at Kotlin/Anko#182 I can see how to catch an exception. Should there be any. Thanks