title: AltBeacon Beacon creation App
body: <p>I need to create a super simple app that just creates a detectable Bluetooth LE beacon, there is no need to transmit any data. I have chosen to use the AltBeacon lybrary, and as such I implemented the app with one of the examples they provide. Still, the app crashes with <code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.bluetooth.le.BluetoothLeAdvertiser.startAdvertising(android.bluetooth.le.AdvertiseSettings, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseCallback)' on a null object reference
  </code>
  I get positive result on both <code>null</code> checks I perform, so I'm not sure what else I could do on my side. Has anyone had any trouble with this library?</p>
  
  <p>The code bellow is 98% the example <a href="https://altbeacon.github.io/android-beacon-library/samples.html" rel="nofollow">available here</a>. I'm using Android 5.0.</p>
  
  <pre><code>import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.widget.Toast;
  
  import org.altbeacon.beacon.Beacon;
  import org.altbeacon.beacon.BeaconParser;
  import org.altbeacon.beacon.BeaconTransmitter;
  
  import java.util.Arrays;
  import java.util.Timer;
  import java.util.TimerTask;
  
  public class MainActivity extends AppCompatActivity {
  
      BeaconTransmitter beaconTransmitter;
      Beacon beacon;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          beacon = new Beacon.Builder()
                  .setId1("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6")
                  .setId2("1")
                  .setId3("2")
                  .setManufacturer(0x0118)
                  .setTxPower(-59)
                  .setDataFields(Arrays.asList(new Long[]{0l}))
                  .build();
  
          if(beacon==null)
              Toast.makeText(getApplicationContext(), "NULL beacon", Toast.LENGTH_LONG).show();
          else
              Toast.makeText(getApplicationContext(), "OK beacon", Toast.LENGTH_LONG).show();
  
          BeaconParser beaconParser = new BeaconParser().setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
          beaconTransmitter = new BeaconTransmitter(getApplicationContext(), beaconParser);
  
          if(beaconTransmitter==null)
              Toast.makeText(getApplicationContext(), "NULL beacon trasmitter", Toast.LENGTH_LONG).show();
          else
              Toast.makeText(getApplicationContext(), "OK beacon trasmitter", Toast.LENGTH_LONG).show();
  
          Timer timer = new Timer();
          timer.schedule(new TimerTask() {
               @Override
              public void run() {
                  beaconTransmitter.startAdvertising(beacon);
              }
          }, 5000);
  
  
      }
  }
  </code></pre>