Skip to content

Commit 04b2962

Browse files
committed
add additional null checks
1 parent 3f7519c commit 04b2962

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

app/src/main/kotlin/io/treehouses/remote/bases/FragmentViewModel.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,14 @@ open class FragmentViewModel(application: Application) : AndroidViewModel(applic
110110
* Load the bluetooth service and update the handler and connection status
111111
*/
112112
fun loadBT() {
113-
mChatService = getApplication<MainApplication>().getCurrentBluetoothService()!!
114-
mChatService.updateHandler(mHandler)
115-
_connectionStatus.value = mChatService.state
113+
val bluetoothService = getApplication<MainApplication>().getCurrentBluetoothService()
114+
if (bluetoothService != null) {
115+
mChatService = bluetoothService
116+
mChatService.updateHandler(mHandler)
117+
_connectionStatus.value = mChatService.state
118+
} else {
119+
_connectionStatus.value = Constants.STATE_NONE
120+
}
116121
}
117122

118123
/**

0 commit comments

Comments
 (0)