title: Android SDK Bluetooth java.lang.NullPointerException
body: <p>I'm implementing a little Bluetooth App in Eclipse with Android SDK and Android Bluetooth. But every time when launching with an Android Virtual Device, my app crashes. I get the following error in LogCat:</p>
  
  <pre><code>E/AndroidRuntime(1170): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothAdapter.startLeScan(android.bluetooth.BluetoothAdapter$LeScanCallback)' on a null object reference
  E/AndroidRuntime(1170): at ble.BluetoothLeService.startScanning(BluetoothLeService.java:241)
  </code></pre>
  
  <p>Here is the part of the code where LogCat said, the error must be.</p>
  
  <pre><code>    // BluetoothLeService - manages connections and data communicationwith    given Bluetooth LE devices.
  public class BluetoothLeService extends Service {
  private final static String TAG = BluetoothLeService.class.getSimpleName();
  
  private BluetoothAdapter mBluetoothAdapter;
  private BluetoothManager mBluetoothManager;
  private boolean mScanning;
  private Handler mHandler;
  private final IBinder mBinder = new LocalBinder();
  
     private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
  
      // Called when new BLE device is discovered
      // Broadcast intent is sent with following extras: device , rssi,
      // additional advertise data
      @Override
      public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
  
          Intent broadcastIntent = new Intent(ACTION_DEVICE_DISCOVERED);
          broadcastIntent.putExtra(DISCOVERED_DEVICE, device);
          broadcastIntent.putExtra(RSSI, rssi);
          broadcastIntent.putExtra(SCAN_RECORD, scanRecord);
  
          sendBroadcast(broadcastIntent);
          Log.i("BLE service", "onLeScan - device: " + device.getAddress() + " - rssi: " + rssi);
      }
  };
  
  // Starts scanning for new BLE devices
  
  
  public void startScanning(final int scanPeriod) {
  
      mHandler.postDelayed(new Runnable() {
          // Called after scanPeriod milliseconds elapsed
          // It stops scanning and sends broadcast
          @Override
          public void run() {
              mScanning = false;
              mBluetoothAdapter.stopLeScan(mLeScanCallback);
  
              Intent broadcastIntent = new Intent(ACTION_STOP_SCAN);
              sendBroadcast(broadcastIntent);
  
          }
      }, scanPeriod);
  
      mScanning = true;
      mBluetoothAdapter.startLeScan(mLeScanCallback);
  
  }
  
  public class LocalBinder extends Binder {
      public BluetoothLeService getService() {
          return BluetoothLeService.this;
      }
  }   
  </code></pre>
  
  <p>I tried a lot of different things, but couldn't find a solution. Can anyone help me out?</p>