Bluetooth discovery app; uncaught handler exception

Discussion in 'Android Hacks and Help' started by chris24300, May 17, 2010.

  1. chris24300
    Offline

    chris24300 New Member

    Joined:
    Jan 7, 2010
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Ratings:
    +0
    Hi, I'm getting an error when I try to search for bluetooth devices and ask the user which device they'd like to connect to. I get an uncaught handler exception, but I do not know how to fix it. This is output from ddms

    Code:
    05-17 14:27:11.405: ERROR/AndroidRuntime(6972): Uncaught handler: thread main exiting due to uncaught exception
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.bluetooth.device.action.FOUND (has extras) } in com.textron.btconfig.BTConfig$1@447af2f8
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972):     at android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run(ActivityThread.java:765)
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972):     at android.os.Handler.handleCallback(Handler.java:587)
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972):     at android.os.Handler.dispatchMessage(Handler.java:92)
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972):     at android.os.Looper.loop(Looper.java:123)
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972):     at android.app.ActivityThread.main(ActivityThread.java:4363)
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972):     at java.lang.reflect.Method.invokeNative(Native Method)
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972):     at java.lang.reflect.Method.invoke(Method.java:521)
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972):     at dalvik.system.NativeStart.main(Native Method)
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972): Caused by: java.lang.NullPointerException
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972):     at com.textron.btconfig.BTConfig$1.onReceive(BTConfig.java:136)
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972):     at android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run(ActivityThread.java:754)
    05-17 14:27:11.413: ERROR/AndroidRuntime(6972):     ... 9 more
    
    Here is my code
    Code:
    ba.startDiscovery();
            // Create a BroadcastReceiver for ACTION_FOUND
            mReceiver = new BroadcastReceiver() 
            {
                public void onReceive(Context context, Intent intent) 
                {
                    String action = intent.getAction();
                    // When discovery finds a device
                    if (BluetoothDevice.ACTION_FOUND.equals(action)) 
                    {
                        Log.d("BT", "Device Found");
                        // Get the BluetoothDevice object from the Intent
                        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                        // add device to a list
                        alert.setTitle("Device Found");
                        alert.setMessage("Device Name: " + device.getName() + ", Device Address: " + device.getAddress());
                        alert.setButton("Connect", new OnClickListener()
                        {
                            public void onClick(DialogInterface dialogI, int which) 
                            {
                                try 
                                {
                                    Log.d("BT", "SUCCESS");
                                } 
                                catch (Exception e) 
                                {
                                    e.printStackTrace();
                                    Log.e("BT", "Alert dialog");
                                }
                            }
                        });
                        
                        alert.setButton2("Next", new OnClickListener() 
                        {
                            public void onClick(DialogInterface dialogI, int which)
                            {
                                return;
                            }
                        });
                        alert.show();
                    }
                }
            };
            // Register the BroadcastReceiver
            IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
            registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroy
    
     
Search tags for this page

android java.lang.nullpointerexception bluetooth

,

android startdiscovery crash

,

error receiving broadcast intent android.bluetooth.device.ac

,

nullpointerexception .device.action.found

,

startdiscovery s4