diff --git a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala index f443475f..8c004112 100644 --- a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala +++ b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala @@ -322,7 +322,7 @@ class Shadowsocks case ignored: RemoteException => // Nothing } // Update the UI - switchButton.setEnabled(true) + if (switchButton != null) switchButton.setEnabled(true) if (State.isAvailable(bgService.getState)) { Crouton.cancelAllCroutons() setPreferenceEnabled(enabled = true) @@ -334,9 +334,9 @@ class Shadowsocks } override def onServiceDisconnected(name: ComponentName) { - switchButton.setEnabled(false) + if (switchButton != null) switchButton.setEnabled(false) try { - bgService.unregisterCallback(callback) + if (bgService != null) bgService.unregisterCallback(callback) } catch { case ignored: RemoteException => // Nothing }