From a28ac5804a926de8cb47b7fc69690f020af5661b Mon Sep 17 00:00:00 2001 From: wangxin Date: Fri, 17 Jun 2016 10:46:53 +0800 Subject: [PATCH] fixed NPE --- .../bluetotohspp/library/BluetoothService.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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) { } }