NullPointerException when trying to read data
See original GitHub issueI am getting the exception below when trying to read data from charactertistic
java.lang.NullPointerException: value must not be null
at com.juul.kable.gatt.Callback.onCharacteristicRead(Callback.kt:110)
at android.bluetooth.BluetoothGatt$1$6.run(BluetoothGatt.java:394)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.os.HandlerThread.run(HandlerThread.java:67)
This is my code from ModelView
init {
val TAG = "HomeViewModel"
val _deviceId = "A8:7E:EA:71:89:54" // Emulator
// val _deviceId = "B4:52:A9:04:E2:88" // Oximeter
viewModelScope.launch {
val adapter = BluetoothAdapter.getDefaultAdapter()
val btd = adapter.getRemoteDevice(_deviceId)
val peripheral = peripheral(btd)
Timber.tag(TAG).d("Connecting to device")
peripheral.connect()
Timber.tag(TAG).d("Connected to device")
delay(2000)
val ch = characteristicOf("0000180A-0000-1000-8000-00805F9B34FB", "00002a29-0000-1000-8000-00805f9b34fb")
val data = peripheral.read(ch)
Timber.tag(TAG).d("Manufacturer data $data")
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to Fix and Avoid NullPointerException in Java - Rollbar
NullPointerException in Java occurs when a variable is accessed which is not pointing to any object and refers to nothing or null.
Read more >NullPointerException when trying to read data from Excel file ...
Issue - Null pointer exception. You are trying to access unavailable cell sheet.getRow(i).getCell(j+1). This is trying to move toward the ...
Read more >Java NullPointerException - Detect, Fix, and Best Practices
NullPointerException is raised in an application when we are trying to do some operation on null where an object is required.
Read more >Null Pointer Exception In Java - GeeksforGeeks
NullPointerException is thrown when program attempts to use an object reference that has the null value. These can be:.
Read more >What Is NullPointerException In Java & How To Avoid It
NullPointerException in Java is a runtime exception. Java assigns a special null value to an object reference. When a program tries to use ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think
GATT_AUTH_FAIL
status depends on user interaction when it accept the pairing request and typing the correct PIN. So, it is ok the consumer of the library handle it.Fixed (to throw the appropriate exception) in 0.5.0.