diff --git a/library/src/main/java/app/akexorcist/bluetotohspp/library/BluetoothService.java b/library/src/main/java/app/akexorcist/bluetotohspp/library/BluetoothService.java index a136ca2..3477b17 100644 --- a/library/src/main/java/app/akexorcist/bluetotohspp/library/BluetoothService.java +++ b/library/src/main/java/app/akexorcist/bluetotohspp/library/BluetoothService.java @@ -228,7 +228,9 @@ public void run() { try { // This is a blocking call and will only return on a // successful connection or an exception - socket = mmServerSocket.accept(); + if (socket != null) { + socket = mmServerSocket.accept(); + } } catch (IOException e) { break; } @@ -258,8 +260,10 @@ public void run() { public void cancel() { try { - mmServerSocket.close(); - mmServerSocket = null; + if (mmServerSocket != null) { + mmServerSocket.close(); + mmServerSocket = null; + } } catch (IOException e) { } }