Rasmus Hjorth Lüdeking Rasmus Hjorth Lüdeking - 1 month ago 5x
Android Question

Android bluetooth crashing application

Having some trouble using

. It's for some reason causing my application to crash.

What I'm doing is displaying an adapter (holding bluetooth names) in a dialogue box. When I run the application and adding
instead of -
the application works fine, but when doing it with
it crashes.

receiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();

if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

AlertDialog.Builder builder = new AlertDialog.Builder(bluetooth.this);
builder.setTitle("Nearby Devices:");
builder.setAdapter(toothadapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {

AlertDialog alert = builder.create();

IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(receiver, filter);

Really need some help as to why this is happening.
The code above this, is all included in
within a


Really need some help as to why this is happening.

Not 100% sure without seeing the stacktrace, but...

BluetoothDevice.getName() returns null if "there was a problem". Now looking at the ArrayAdapter's add() method we can see that within it mObjects.add(object) is called where mObjects is of type List<T> (an interface). In its turn the List<T>'s add() method throws a few exeptions one of which is

java.lang.NullPointerException if the specified element is null and this list does not permit null elements.

If that's the case you might consider using anything else instead of null device names.