java.io.IOException: Not able to register SDP record for mango at android.bluetooth.BluetoothAdapter.createNewRfcommSocketAndRecord(BluetoothAdapter.java:890) at android.bluetooth.BluetoothAdapter.listenUsingRfcommWithServiceRecord(BluetoothAdapter.java:813) at com.card.test.receivecard$AcceptThread.<init>(receivecard.java:118) at com.card.test.receivecard.onStart(receivecard.java:96) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129) at android.app.Activity.performStart(Activity.java:3797) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1620) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) at android.app.ActivityThread.access$1500(ActivityThread.java:117) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3683) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636) at dalvik.system.NativeStart.main(Native Method) null threadid=9: thread exiting with uncaught exception (group=0x401f6560) ATAL EXCEPTION: Thread-10 java.lang.NullPointerException at com.card.test.receivecard$AcceptThread.run(receivecard.java:132)
我的接收端代码片段如下:
private class AcceptThread extends Thread { private final BluetoothServerSocket mmServerSocket; private InputStream mmInStream;
public void run() { BluetoothSocket socket = null;
// Keep listening until exception occurs or a socket is returned while (true) { try { System.out.println(mmServerSocket);//由打印信息知mmServerSocket为null socket = mmServerSocket.accept(); //所以这里出错了 } catch (IOException e) { e.printStackTrace(); finish(); break; } // If a connection was accepted if (socket != null) { try { 以下省略。。。 }
发送端代码片段如下:
private class ClientThread extends Thread { private final BluetoothSocket msocket; private final BluetoothDevice mdevice; final String SPP_UUID = "00001101-0000-1000-8000-00805F9B34FB"; UUID uuid = UUID.fromString(SPP_UUID);