question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullPointerException when trying to read data

See original GitHub issue

I 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:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
francismarianocommented, Apr 27, 2021

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.

0reactions
twyattcommented, Apr 28, 2021

Fixed (to throw the appropriate exception) in 0.5.0.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found