title: Basic Bluetooth application does not work
body: <p>I want to realize data transfer with a remote Bluetooth server,Hence I began to explore androids Bluetooth functionality,I'm going step by step ,now I got stuck in a program. After loading the program to the emulator, it responds "Adil_Bluetooth_1st had stopped".</p>
  
  <p>I provide you my files:</p>
  
  <p><strong>XML file:</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".MainActivity" &gt;
  
      &lt;TextView
          android:id="@+id/acceleration"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:text="X: Y: Z:"
          android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
      &lt;ProgressBar
          android:id="@+id/progressBarX"
          style="?android:attr/progressBarStyleHorizontal"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/acceleration"
          android:layout_alignParentRight="true"
          android:layout_below="@+id/acceleration"
          android:layout_marginLeft="19dp"
          android:layout_marginRight="19dp"
          android:layout_marginTop="40dp" /&gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="140dp"
          android:layout_height="wrap_content"
          android:layout_alignRight="@+id/progressBarX"
          android:layout_alignTop="@+id/acceleration"
          android:text="               Noise Margin" /&gt;
  
      &lt;TextView
          android:id="@+id/textView2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/progressBarX"
          android:layout_below="@+id/progressBarX"
          android:text="X-axis" /&gt;
  
      &lt;TextView
          android:id="@+id/textView3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/progressBarZ"
          android:layout_below="@+id/progressBarY"
          android:text="Y-axis" /&gt;
  
      &lt;ProgressBar
          android:id="@+id/progressBarY"
          style="?android:attr/progressBarStyleHorizontal"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/textView2"
          android:layout_alignRight="@+id/progressBarX"
          android:layout_below="@+id/textView2"
          android:layout_marginTop="72dp" /&gt;
  
      &lt;EditText
          android:id="@+id/eText"
          android:layout_width="50dp"
          android:layout_height="45dp"
          android:layout_alignLeft="@+id/textView1"
          android:layout_alignTop="@+id/textView1"
          android:ems="10"
          android:inputType="numberDecimal" &gt;
  
          &lt;requestFocus /&gt;
      &lt;/EditText&gt;
  
      &lt;TextView
          android:id="@+id/textView4"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/progressBarZ"
          android:layout_alignTop="@+id/progressBarZ"
          android:layout_marginTop="20dp"
          android:text="Z-axis" /&gt;
  
      &lt;ProgressBar
          android:id="@+id/progressBarZ"
          style="?android:attr/progressBarStyleHorizontal"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/progressBarY"
          android:layout_alignRight="@+id/progressBarY"
          android:layout_below="@+id/textView3"
          android:layout_marginTop="84dp" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And this is my <code>ActivityMain.java</code> file:</p>
  
  <pre><code>package com.example.adil_bluetooth_1st;
  
  import java.util.Set;
  
  import javax.xml.datatype.Duration;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.Menu;
  import android.widget.ArrayAdapter;
  import android.widget.Toast;
  import android.bluetooth.*;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.content.IntentFilter;
  
  public class Bluetooth extends Activity {
  
      private BluetoothAdapter mBluetoothAdapter;
      Integer REQ_BT_ENABLE=1;
      private ArrayAdapter&lt;String&gt; mArrayAdapter;
      Set&lt;BluetoothDevice&gt; pairedDevices;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_bluetooth);
          mBluetoothAdapter=BluetoothAdapter.getDefaultAdapter();
          String Status;
          if(mBluetoothAdapter==null)
          {
              Toast.makeText(this, "Device doesn't support Bluetooth", Toast.LENGTH_LONG).show();
  
          }
          /*
           * checking whether Bluetooth is enabled ,if not enable it!
           * */
          if(mBluetoothAdapter.isEnabled())
          {
              String mydeviceadress=mBluetoothAdapter.getAddress();
              String mydevicename=mBluetoothAdapter.getName();
              Status="My Device Name is:"+mydevicename+"\nThe Adress is:"+mydeviceadress;
              Toast.makeText(this, Status, Toast.LENGTH_LONG).show();
          }
          else
          {
               Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
               startActivityForResult(enableBtIntent, REQ_BT_ENABLE);
               Toast.makeText(this, "Enabling Bluetooth!!", Toast.LENGTH_LONG).show();
          }
          /*
           * Getting paired devices and saving them on an ArrayAdapter
           * */
          pairedDevices = mBluetoothAdapter.getBondedDevices();
          // If there are paired devices
          if (pairedDevices.size() &gt; 0) {
              // Loop through paired devices
              for (BluetoothDevice device : pairedDevices) {
                  // Add the name and address to an array adapter to show in a ListView
                  mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
              }
          }
          /*Create a BroadcastReceiver for ACTION_FOUND
           *
           * */
  
  
          final BroadcastReceiver Receiver = new BroadcastReceiver() {
              public void onReceive(Context context, Intent intent) {
                  String action = intent.getAction();
                  // When discovery finds a device
                  if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                      // Get the BluetoothDevice object from the Intent
                      BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                      // Add the name and address to an array adapter to show in a ListView
                      mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
                  }
              }
          };
          // Register the BroadcastReceiver
          IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
          registerReceiver(Receiver, filter);
  
  
          /*
           * to make the device discoverable
           * */
          Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
          discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
          startActivity(discoverableIntent);
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.bluetooth, menu);
          return true;
      }
  
  }
  </code></pre>
  
  <p><strong>LogCat messages:</strong></p>
  
  <pre><code>&gt; 04-04 16:41:58.051: E/BluetoothAdapter(1082): Bluetooth binder is null
  &gt; 04-04 16:41:58.111: D/AndroidRuntime(1082): Shutting down VM 04-04
  &gt; 16:41:58.111: W/dalvikvm(1082): threadid=1: thread exiting with
  &gt; uncaught exception (group=0x40a71930) 04-04 16:41:58.131:
  &gt; E/AndroidRuntime(1082): FATAL EXCEPTION: main 04-04 16:41:58.131:
  &gt; E/AndroidRuntime(1082): java.lang.RuntimeException: Unable to start
  &gt; activity
  &gt; 
  
  ComponentInfo{com.example.adil_bluetooth_1st/com.example.adil_bluetooth_1st.Bluetooth}:
  &gt; java.lang.NullPointerException 04-04 16:41:58.131:
  &gt; E/AndroidRuntime(1082):   at
  &gt; android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
  &gt; 04-04 16:41:58.131: E/AndroidRuntime(1082):   at
  &gt; android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  &gt; 04-04 16:41:58.131: E/AndroidRuntime(1082):   at
  &gt; android.app.ActivityThread.access$600(ActivityThread.java:141) 04-04
  &gt; 16:41:58.131: E/AndroidRuntime(1082):     at
  &gt; android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  &gt; 04-04 16:41:58.131: E/AndroidRuntime(1082):   at
  &gt; android.os.Handler.dispatchMessage(Handler.java:99) 04-04
  &gt; 16:41:58.131: E/AndroidRuntime(1082):     at
  &gt; android.os.Looper.loop(Looper.java:137) 04-04 16:41:58.131:
  &gt; E/AndroidRuntime(1082):   at
  &gt; android.app.ActivityThread.main(ActivityThread.java:5041) 04-04
  &gt; 16:41:58.131: E/AndroidRuntime(1082):     at
  &gt; java.lang.reflect.Method.invokeNative(Native Method) 04-04
  &gt; 16:41:58.131: E/AndroidRuntime(1082):     at
  &gt; java.lang.reflect.Method.invoke(Method.java:511) 04-04 16:41:58.131:
  &gt; E/AndroidRuntime(1082):   at
  &gt; com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  &gt; 04-04 16:41:58.131: E/AndroidRuntime(1082):   at
  &gt; com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 04-04
  &gt; 16:41:58.131: E/AndroidRuntime(1082):     at
  &gt; dalvik.system.NativeStart.main(Native Method) 04-04 16:41:58.131:
  &gt; E/AndroidRuntime(1082): Caused by: java.lang.NullPointerException
  &gt; 04-04 16:41:58.131: E/AndroidRuntime(1082):   at
  &gt; com.example.adil_bluetooth_1st.Bluetooth.onCreate(Bluetooth.java:38)
  &gt; 04-04 16:41:58.131: E/AndroidRuntime(1082):   at
  &gt; android.app.Activity.performCreate(Activity.java:5104) 04-04
  &gt; 16:41:58.131: E/AndroidRuntime(1082):     at
  &gt; android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
  &gt; 04-04 16:41:58.131: E/AndroidRuntime(1082):   at
  &gt; android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
  &gt; 04-04 16:41:58.131: E/AndroidRuntime(1082):   ... 11 more
  </code></pre>