We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class WeatherLocalDataSourceImpl is thrown a null pointer exception
so returning an empty DBWeather if it's null fixing the issue
override suspend fun getWeather(): DBWeather? = withContext(ioDispatcher) { if (weatherDao.getWeather() == null) { return@withContext DBWeather( cityId = 0, cityName = "None", wind = Wind( speed = 0.0, deg = 0 ), networkWeatherDescription = listOf(), networkWeatherCondition = NetworkWeatherCondition( temp = 0.0, pressure = 0.0, humidity = 0.0 ) ) } else { return@withContext weatherDao.getWeather() } }
The text was updated successfully, but these errors were encountered:
and you may need to update observeviewmodel function in home fragment also to handle if networkWeatherDescription is empty
weather.observe(viewLifecycleOwner) { weather -> weather?.let { prefs.saveCityId(it.cityId)
if (prefs.getSelectedTemperatureUnit() == activity?.resources?.getString(R.string.temp_unit_fahrenheit)) it.networkWeatherCondition.temp = convertCelsiusToFahrenheit(it.networkWeatherCondition.temp) binding.weather = it if (it.networkWeatherDescription.isNotEmpty()) { binding.networkWeatherDescription = it.networkWeatherDescription.first() } else { binding.networkWeatherDescription = null } } }
Sorry, something went wrong.
No branches or pull requests
class WeatherLocalDataSourceImpl
is thrown a null pointer exception
so returning an empty DBWeather if it's null fixing the issue
override suspend fun getWeather(): DBWeather? = withContext(ioDispatcher) {
if (weatherDao.getWeather() == null) {
return@withContext DBWeather(
cityId = 0,
cityName = "None",
wind = Wind(
speed = 0.0,
deg = 0
),
networkWeatherDescription = listOf(),
networkWeatherCondition = NetworkWeatherCondition(
temp = 0.0,
pressure = 0.0,
humidity = 0.0
)
)
} else {
return@withContext weatherDao.getWeather()
}
}
The text was updated successfully, but these errors were encountered: