Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

ConnectThread NullPointerException when the BT has been manually disabled #92

Open
artetrad opened this issue Apr 12, 2018 · 0 comments

Comments

@artetrad
Copy link

Hi, I am using the DeviceList Activity in order to choose a device. But if I disable the BT, when viewing the DeviceList screen and choose one of the already rendered results, then in my onActivityResult() I get an NPE when trying to connect.

Specifically, in the BluetoothService.java, the ConnectThread's run method, the mmSocket.connect(); line gets a NPE, when executed. Since you already handle the IOException, would it be possible to add another NullPointerException catch block below?

public void run() {
            // Always cancel discovery because it will slow down a connection
            mAdapter.cancelDiscovery();

            // Make a connection to the BluetoothSocket
            try {
                // This is a blocking call and will only return on a
                // successful connection or an exception
                mmSocket.connect();
            } catch (IOException e) {
                // Close the socket
                try {
                    mmSocket.close();
                } catch (IOException e2) { }
                connectionFailed();
                return;
            }

            // Reset the ConnectThread because we're done
            synchronized (BluetoothService.this) {
                mConnectThread = null;
            }

            // Start the connected thread
            connected(mmSocket, mmDevice, mSocketType);
        }

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant