ykasidit / bluetooth_gnss

Bluetooth GNSS app on Google Play Store
https://play.google.com/store/apps/details?id=com.clearevo.bluetooth_gnss&hl=en&gl=US
GNU General Public License v2.0
63 stars 19 forks source link

NPE in MainActivity #5

Closed auricgoldfinger closed 3 years ago

auricgoldfinger commented 3 years ago

I still don't know how to reproduce it and I'm still trying to find a solution for it, but sometimes I get a stacktrace in a Toast message:

WARNING: check _is_bt_connected failed: PlatformException(error, Attempt to invoke virtual method 'boolean com.clearevo.libbluetooth_gnss_service.bluetooth_gnss_service.is_ntrip_connected()' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.clearevo.libbluetooth_gnss_service.bluetooth_gnss_service.is_ntrip_connected()' on a null object reference
   at com.clearevo.bluetooth_gnss.MainActivity$2.onMetodCall(MainActivity.java:180)
   at io.flutter.plugin.common...

https://github.com/ykasidit/bluetooth_gnss/blob/391f2fb1c9a5dc95ba0ab8be0ec055fbb90146ae/android/app/src/main/java/com/clearevo/bluetooth_gnss/MainActivity.java#L180

The code could be changed with result.success(m_service != null && m_service.is_ntrip_connected()); but I'm trying to find out what causes m_service to be null...

Work around: close the app, swipe it away and reopen 😃

auricgoldfinger commented 3 years ago

So I did some research and due to the async character of the events, you just can't be sure. There were more checks for null on the m_service so it seems to be the best way to solve it anyway. Since pull request #4 isn't merged yet, I pushed it into that one 😃