Fix: KotlinNullPointerException in LiveData when attempting to get a value

Adding a null check to avoid KotlinNullPointerException. Replacing isEmpty() call with isNullOrEmpty().
This commit is contained in:
Jhansi 2020-01-23 10:06:11 -08:00
parent d70a45c3a1
commit 57995e8080
2 changed files with 2 additions and 2 deletions

View File

@ -114,7 +114,7 @@ class DevByteViewModel(application: Application) : AndroidViewModel(application)
} catch (networkError: IOException) { } catch (networkError: IOException) {
// Show a Toast error message and hide the progress bar. // Show a Toast error message and hide the progress bar.
if(playlist.value!!.isEmpty()) if(playlist.value.isNullOrEmpty())
_eventNetworkError.value = true _eventNetworkError.value = true
} }
} }

View File

@ -114,7 +114,7 @@ class DevByteViewModel(application: Application) : AndroidViewModel(application)
} catch (networkError: IOException) { } catch (networkError: IOException) {
// Show a Toast error message and hide the progress bar. // Show a Toast error message and hide the progress bar.
if(playlist.value!!.isEmpty()) if(playlist.value.isNullOrEmpty())
_eventNetworkError.value = true _eventNetworkError.value = true
} }
} }