title: BluetoothLeScanner null object reference
body: <p>I have a problem regarding my Bluetooth app. When I enable Bluetooth before starting up the app everything works alright. But when I don't, my app will ask permission to enable Bluetooth via the turnOn method. But when I press my onScan button I get a error stating:</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.bluetooth.le.BluetoothLeScanner.startScan(android.bluetooth.le.ScanCallback)' on a null object reference
  </code></pre>
  
  <p>here is my onCreate method:</p>
  
  <pre><code> protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      //Set layout
      setContentView(R.layout.activity_main);
      //Bluetooth
      // BluetoothManager
      final BluetoothManager BTManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
      BTAdapter = BTManager.getAdapter();
      // BluetoothLescanner
      BTScanner = BTAdapter.getBluetoothLeScanner();
      //Turn on BT
      turnOn();
      //Ask permission for location.
      requestPermission();
  }
  </code></pre>
  
  <p>My ques is that, BTScanner is made before the turnOn method is called, making the BTScanner a null object. </p>
  
  <p>Any help regarding this problem would be greatly.</p>
  
  <p>Kind regards,</p>
  
  <p>Binsento</p>