While coding an android app in Kotlin I came across this error:
I am using the OpenWeatherMapApi and from the API I am trying to grab the Forecast Data. And I was able to pull the Forecast data thanks to okhttp3 and Gson but now my issue is displaying that data. I created and a new class for a custom ArrayAdapter where I try to display in the textView that I created, but I am completely at a loss as to why I keep getting the error the array shouldn't have a size of 1 but it ends up having it
Code
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.weather_row.view.*
class ForecastAdapter(val forecast: Forecast) : RecyclerView.Adapter<ForecastData>(){
override fun getItemCount(): Int {
return forecast.list.count()
}
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): ForecastData {
val layoutInflator = LayoutInflater.from(p0?.context)
val cellForRow = layoutInflator.inflate(R.layout.weather_row, p0, false)
return ForecastData(cellForRow)
}
override fun onBindViewHolder(p0: ForecastData, p1: Int) {
val getWeather = forecast.list[p1]
val clouds = getWeather.weather[p1]
p0.view.textView_text_clouds.text = clouds.main
}
}
class ForecastData(val view: View): RecyclerView.ViewHolder(view){
}