BLE GATTCALLBACK에서 disconnect 경우에 재연결하려고 합니다.
Autoconnect false로 하였습니다.
주소는 밑에 로그창에 보듯이 받아오는데
mService.connectDevice에서 nullpointerexception이 나는 거같은데 왜 그런건가요?
mService가 Nullpointerexception인데 왜 널포인터인지 모르겠습니다.ㅠㅠ
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
mState = STATE_CONNECTED;
check_mState=mState;
mHandler.sendMessage(msg);
Log.d(TAG, "# Connected to GATT server.");
mHandler.obtainMessage(ServiceClass.MESSAGE_STATE_CHANGE, STATE_CONNECTED, 0).sendToTarget();
gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
mState = STATE_IDLE;
check_mState=mState;
Log.d(TAG, "# Disconnected from GATT server.");
mHandler.obtainMessage(ServiceClass.MESSAGE_STATE_CHANGE, STATE_IDLE, 0).sendToTarget();
mBluetoothGatt = null;
mGattServices.clear();
mDefaultService = null;
mGattCharacteristics.clear();
mWritableCharacteristics.clear();
mDefaultChar = null;
mDefaultDevice = null;
Log.d(TAG, bluetooth_addr);
mService.connectDevice(bluetooth_addr);
}
}
W/BluetoothGatt(11372): Unhandled exception in callback
java.lang.NullPointerException: Attempt to invoke virtual method 'void healthall.company.water_bottle_ble.ServiceClass.connectDevice(java.lang.String)' on a null object reference
at healthall.company.water_bottle_ble.BleManager$1.onConnectionStateChange(BleManager.java:489)
at android.bluetooth.BluetoothGatt$1.onClientConnectionState(BluetoothGatt.java:186)
at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:70)
at android.os.Binder.execTransact(Binder.java:461)