I was following the tutorial for PSoC® Video Tutorial Series: How to Create Android Apps to Interact with Cypress BLE when I downloaded the source code and tried to run the program. The PSoC code appears to work correctly because I could control the red LED and receive CapSense data using the CySmart app on my phone.
When I loaded the PSoC code in Creator 4.1, it did ask for me to hit Project > Update Components because the design "uses an older version of a component than is available in your dependencies." This seemed to work fine. Other than that, there were no changes to any files.
The Android app works up until the point you hit the "Discover Services and Characteristics" button. The last couple of lines in the console of Android Studio 3.0 reveal the error.
D/MainActivity: Connected to Device
D/BluetoothGatt: discoverServices() - device: 00:A0:50:AE:79:E3
I/Choreographer: Skipped 261 frames! The application may be doing too much work on its main thread.
D/BluetoothGatt: onSearchComplete() = Device=00:A0:50:AE:79:E3 Status=0
W/BluetoothGatt: Unhandled exception in callback
java.lang.NullPointerException: Attempt to invoke virtual method 'android.bluetooth.BluetoothGattCharacteristic android.bluetooth.BluetoothGattService.getCharacteristic(java.util.UUID)' on a null object reference
Debugging that area of code, I see that line 376 of PSoCCapSenseLedService.java is returning null so the error is happening on the next use of mService.
line 376: BluetoothGattService mService = gatt.getService(UUID.fromString(capsenseLedServiceUUID));
The uuid being passed to getService() is 00000000-0000-1000-8000-00805f9b34f0. mServices has 3 services and their UUIDs are:
getService() loops through these and does not find a match for the uuid it was passed and so it returns null.
Can someone help me with the fix for this?