Note that there are some explanatory texts on larger screens.

plurals
  1. POBluetoothChat ConnectedThread crash
    primarykey
    data
    text
    <p>I'm getting this problem while executing a modified BluetoothChat app. The app shows the devices, starts connecting to it, and then crashes. I've been testing this and it happens on this thread.</p> <p>Here is the code and the LogCat:</p> <pre><code>public class ConnectedThread extends Thread { // Debugging private static final String TAG = "BluetoothChatService"; private static final boolean D = true; public ConnectedThread(BluetoothSocket socket) { Log.d(TAG, "create ConnectedThread"); GlobalVar.mmSocket = socket; InputStream tmpIn = null; OutputStream tmpOut = null; /**Get the input and output streams, using temp objects because member streams are final*/ try { tmpIn = socket.getInputStream(); tmpOut = socket.getOutputStream(); } catch (IOException e) {Log.e(TAG, "temp sockets not created", e); } GlobalVar.mmInStream = tmpIn; GlobalVar.mmOutStream = tmpOut; } @Override public void run() { Log.i(TAG, "BEGIN mConnectedThread"); byte[] buffer = new byte[1024]; // buffer store for the stream int bytes; // bytes returned from read() /**Keep listening to the InputStream until an exception occurs*/ while (true) { try { if (D) Log.d(TAG, "starting"); /**Read from the InputStream*/ bytes = GlobalVar.mmInStream.read(buffer); /**Send the obtained bytes to the UI activity*/ GlobalVar.mHandler.obtainMessage(GlobalVar.MESSAGE_READ, bytes, -1, buffer).sendToTarget(); } catch (IOException e) { Log.e(TAG, "disconnected", e); GlobalVar.mTransmission.connectionLost(); /**Start the service over to restart listening mode*/ if (D) Log.d(TAG, "arrives"); ConnectedThread.this.start(); //This could be wrong! break; } } } /** * Write to the connected OutStream. * @param buffer The bytes to write */ public void write(byte[] buffer) { try { GlobalVar.mmOutStream.write(buffer); /**Share the sent message back to the UI Activity*/ GlobalVar.mHandler.obtainMessage(GlobalVar.MESSAGE_WRITE, -1, -1, buffer).sendToTarget(); } catch (IOException e) {} } /**Call this from the main activity to shutdown the connection*/ public void cancel() { try { GlobalVar.mmSocket.close(); } catch (IOException e) { } } </code></pre> <p>}</p> <p>/This is the LogCat where it can be seen that it enters in the While and then crashes.</p> <pre><code>07-23 12:22:55.560: D/AbsListView(27386): unregisterIRListener() is called 07-23 12:22:55.590: D/BluetoothUtils(27386): isSocketAllowedBySecurityPolicy start : device null 07-23 12:22:55.590: W/BluetoothAdapter(27386): getBluetoothService() called with no BluetoothManagerCallback 07-23 12:22:55.600: E/SpannableStringBuilder(27386): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 07-23 12:22:55.600: E/SpannableStringBuilder(27386): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 07-23 12:22:55.620: D/AbsListView(27386): onDetachedFromWindow 07-23 12:22:55.620: D/AbsListView(27386): unregisterIRListener() is called 07-23 12:22:55.620: D/AbsListView(27386): onDetachedFromWindow 07-23 12:22:55.620: D/AbsListView(27386): unregisterIRListener() is called 07-23 12:22:57.032: D/BluetoothChatService(27386): create ConnectedThread 07-23 12:22:57.052: D/AndroidRuntime(27386): Shutting down VM 07-23 12:22:57.052: I/BluetoothChatService(27386): BEGIN mConnectedThread 07-23 12:22:57.052: D/BluetoothChatService(27386): starting 07-23 12:22:57.052: W/dalvikvm(27386): threadid=1: thread exiting with uncaught exception (group=0x41d58ac8) 07-23 12:22:57.052: E/AndroidRuntime(27386): FATAL EXCEPTION: main 07-23 12:22:57.052: E/AndroidRuntime(27386): java.lang.NullPointerException 07-23 12:22:57.052: E/AndroidRuntime(27386): at com.example.btaplication.BTActivity$1.handleMessage(BTActivity.java:289) 07-23 12:22:57.052: E/AndroidRuntime(27386): at android.os.Handler.dispatchMessage(Handler.java:99) 07-23 12:22:57.052: E/AndroidRuntime(27386): at android.os.Looper.loop(Looper.java:137) 07-23 12:22:57.052: E/AndroidRuntime(27386): at android.app.ActivityThread.main(ActivityThread.java:5328) 07-23 12:22:57.052: E/AndroidRuntime(27386): at java.lang.reflect.Method.invokeNative(Native Method) 07-23 12:22:57.052: E/AndroidRuntime(27386): at java.lang.reflect.Method.invoke(Method.java:511) 07-23 12:22:57.052: E/AndroidRuntime(27386): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 07-23 12:22:57.052: E/AndroidRuntime(27386): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 07-23 12:22:57.052: E/AndroidRuntime(27386): at dalvik.system.NativeStart.main(Native Method) 07-23 12:28:07.475: I/Process(27386): Sending signal. PID: 27386 SIG: 9 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload