-1

This is the error i am getting:

Attempt to invoke virtual method 'void android.bluetooth.le.BluetoothLeScanner.startScan(android.bluetooth.le.ScanCallback)' on a null object reference

I tried adding coarse_location permissions both in manifest and at run time but it didn't work and also turned on location. Can someone help me in this.

I use this to scan Low energy devices.

mBluetoothLeScanner.startScan(mLeScanCallback);

This is my scancallback.

final ScanCallback mLeScanCallback = new ScanCallback() {
            @Override
            public void onScanResult(int callbackType, ScanResult result) {
                final int new_rssi = result.getRssi();
                addDevice(result, new_rssi);
                super.onScanResult(callbackType, result);
            }
kAliert
  • 768
  • 9
  • 21

1 Answers1

0

2 possibilities come to my mind:

  1. Bluetooth is disabled - this would cause NPE when trying to start a BLE scan
  2. Check if you're Location is enabled. Go to Settings > Location. BLE requires device's location to work, if you start a BLE scan when Location is disabled you won't receive any results
ansorod
  • 367
  • 1
  • 5