
install에 성공하여 도시 탭버튼도 작동하고 Home, List 전환도 되지만
Home fragment에 기상데이터를 표시하지 못하고,List의 시간별 기상데이터도 표시되지 안습니다.


작성한 코드 및 에러 메세지
package com.example.spartaweatherapp.model
import android.util.Log
import com.example.spartaweatherapp.RainStatus
import com.example.spartaweatherapp.SkyStatus
import com.example.spartaweatherapp.WeatherData
import com.google.gson.annotations.SerializedName
data class WeatherModel(
@SerializedName("responce")
val response: Response
) {
fun toWeatherData(): WeatherData {
return response.body.items.item.toWeatherData()
}
private fun Any.toWeatherData(): WeatherData {
return toWeatherData()
}
private fun List<Item>.toWeatherData(): WeatherData {
val items = this
val time = items.find { it.category == "SKY" }?.fcstTime ?: "--:--"
val skyStatus = items.find { it.category == "SKY" }?.fcstValue ?: ""
val rainStatus = items.find { it.category == "PTY" }?.fcstValue ?: ""
val rainPercent = items.find { it.category == "POP" }?.fcstValue ?: ""
val rainAmount = items.find { it.category == "PCP" }?.fcstValue ?: ""
val temp = items.find { it.category == "TMP" }?.fcstValue ?: ""
val windSpeed = items.find { it.category == "WSD" }?.fcstValue ?: ""
val humidity = items.find { it.category == "REH" }?.fcstValue ?: ""
return WeatherData(
time = time,
skyStatus = SkyStatus.entries.firstOrNull { it.value == skyStatus.toInt() }
?: SkyStatus.GOOD,
rainAmount = rainAmount,
rainPercent = rainPercent,
rainState = RainStatus.entries.firstOrNull { it.value == rainStatus.toInt() }
?: RainStatus.NONE,
temperature = temp,
windSpeed = windSpeed,
humidity = humidity
)
}
fun toWeatherList(count: Int): List<WeatherData> {
val list = mutableListOf<WeatherData>()
val items = response.body.items.item
val baseTime = items.first()?.baseTime
var nextTime = baseTime?.nextTime()
repeat(count) {
val subItems = items.filter { it!!.fcstTime == nextTime }.toList()
val weatherData = subItems.toWeatherData()
Log.d("WeatherData", "time: $nextTime, data: $weatherData")
list.add(weatherData)
nextTime = nextTime!!.nextTime()
}
return list
}
private fun String.nextTime(): String {
if (this.length != 4) {
throw IllegalArgumentException("잘못된 시간 형식")
}
val hour = this.substring(0, 2).toInt()
val minute = this.substring(2, 4).toInt()
if (hour !in 0..23 || minute !in 0..59) {
throw IllegalArgumentException("잘못된 시간 범위")
}
val nextHour = if (hour == 23) 0 else hour + 1
return "%02d%02d"
RetrofitInstance.kt 에 Url 첨부
------------------------------------------
object RetrofitInstance {
private const val BASE_URL = "http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0"
WeatherService.kt 에 API_ KEY 발급받은 첨부
----------------------------------------------
private const val API_KEY = ""PVTuVfsMbN%2FLK%2Bdn*********RuuH3lCD28HfPLvIyP5ARMVLFzm4S3M9cc7gYsuRCQsg6jsvWwnEXueZFiPDw%3D%3D""
Logcat 에러에서

WetherModel.kt 에서 toWeatherData 가 에러표시가 있어서 private fun 만든 것이 잘못된 것 같습니다.
