-1

I am trying to perform a ble write to a microprocessor on an android application and something weird is happening.

To start, the log for the error is below:

Unhandled exception in callback
                                                                                   java.lang.NullPointerException
                                                                                       at android.bluetooth.BluetoothGatt.writeCharacteristic(BluetoothGatt.java:874)
                                                                                       at com.example.tannerhenry.standalone.ConfigurationActivity.setWriteSensor(ConfigurationActivity.java:248)
                                                                                       at com.example.tannerhenry.standalone.ConfigurationActivity.access$100(ConfigurationActivity.java:31)
                                                                                       at com.example.tannerhenry.standalone.ConfigurationActivity$4.onServicesDiscovered(ConfigurationActivity.java:289)
                                                                                       at android.bluetooth.BluetoothGatt$1.onSearchComplete(BluetoothGatt.java:295)
                                                                                       at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:215)
                                                                                       at android.os.Binder.execTransact(Binder.java:404)
                                                                                       at dalvik.system.NativeStart.run(Native Method)

After a debugging for a bit I noticed that the characteristic that I am trying to write to isn't being discovered and therefore explains why the null pointer exception occurs.

The problem is that the characteristic is definitely being advertised because I downloaded LightBlue on my iPhone and the characteristic appears. This brings me to believe that I have made a mistake in initializing characteristics but I after I downloaded Bluetooth LE scanner from the app store, it still acts the same way as my app.

Is there a difference in the way iOS and android getCharacteristics?

Note: I have had this issue before, the solution was re-downloading the app a few times and it eventually read the characteristic. But I did a data clear on my tablet and now it is doing the same thing as before and re-downloading isn't fixing it this time.

Any help would be appreciated and I can provide more code if necessary.

thenry
  • 85
  • 1
  • 12
  • You shouldn't create your own BluetoothGattCharacteristic objects but obtain them by first doing gatt.discoverServices(), and then in the onServicesDiscovered callback use gatt.getService(uuid) or gatt.getServices() to get the services. Then you can use service.getCharacteristic(uuid) or service.getCharacteristics() to get your BluetoothGattCharacteristic objects. – Emil Apr 04 '17 at 01:10
  • Yes I call gatt.discoverServices in the connection state of my onConnectionStateChange callback so this is not the problem. Do you know how many characteristics I can put into a service? @Emil – thenry Apr 04 '17 at 19:45
  • There is no limitation except that the gatt db cannot have more than 0xffff handles or so. – Emil Apr 04 '17 at 23:47

1 Answers1

0

The problem was fixed by manually forgetting the previously paired device and repairing.

thenry
  • 85
  • 1
  • 12