alexkendall / react-native-bluetooth-cross-platform

Cross-Platform Bluetooth & WiFi React Native Module. Powered by underdark http://underdark.io/.
179 stars 35 forks source link

Attempt to invoke virtual method 'void java.util.Timer.cancel()' on a null object reference #36

Closed azanli closed 6 years ago

azanli commented 6 years ago

NetworkManager.js

    @ReactMethod
    public void stopAdvertising() {
        if(this.type == User.PeerType.ADVERTISER_BROWSER) {
            this.type = User.PeerType.BROWSER;
            this.networkCommunicator.initTransport("WIFI-BT", this.type);
            return;
        }
        this.type = User.PeerType.OFFLINE;
        this.networkCommunicator.stopTransport();
    }

NetworkCommunicator.java

    @Override
    public void stopTransport() {
        broadcastTimer.cancel();
        broadcastTimer = null;
        isRunning = false;
    }

App is crashing upon calling stopAdvertising() with the above error but I'm certain that both "Advertise" and "Browse" are currently on when it's called. It happens after some time has passed while Advertising and Browsing. Would there maybe be a way to check first whether broadcastTimer is currently in progress before invoking cancel() on it within NetworkCommunicator.java?

azanli commented 6 years ago

It seems that the problem has stopped since I've started using the check that I mentioned in the PR. Will report back here if it occurs again.