public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
BluetoothManager btManager = new BluetoothManager(this);
setContentView(R.layout.main);
if (!btManager.isEnabled()) {
btManager.requestBluetoothEnable();
discoveryStarted = false;
} else {
if (btManager.isDeviceSetNullOrEmpty()) {
btManager.startDiscovery();
discoveryStarted = true;
}
}
}
@Override
public void onResume(){
super.onResume();
if( btManager.isEnabled() && discoveryStarted == false ){
I get a NullPointer exception here even though I initialized my btManager class ( a wrapper around a few Bluetooth classes .
BluetoothManager btManager = new BluetoothManager(this);
is only declared locally in the onCreate.
Try putting BlueToothManager btManager;
as a class-wide field (just below class declaration). Then, inside oncreate:
btManager = new BluetoothManager(this);
Then, see if you can access it without the nullpointer inside onResume!