tanguyantoine/react-native-music-control

Null exceptions

Closed this issue · 6 comments

Description

Null exceptions on v1.2.1

  1. java.lang.NullPointerException
java.lang.NullPointerException: 
  at com.tanguyantoine.react.MusicControlNotification$NotificationService.forceForeground (MusicControlNotification.java:220)
  at com.tanguyantoine.react.MusicControlModule$1.onServiceConnected (MusicControlModule.java:243)
  at android.app.LoadedApk$ServiceDispatcher.doConnected (LoadedApk.java:1667)
  at android.app.LoadedApk$ServiceDispatcher$RunConnection.run (LoadedApk.java:1696)
  at android.os.Handler.handleCallback (Handler.java:790)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:169)
  at android.app.ActivityThread.main (ActivityThread.java:6521)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
  1. java.lang.RuntimeException
java.lang.RuntimeException: 
  at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:4552)
  at android.app.ActivityThread.access$2100 (ActivityThread.java:274)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2134)
  at android.os.Handler.dispatchMessage (Handler.java:107)
  at android.os.Looper.loop (Looper.java:237)
  at android.app.ActivityThread.main (ActivityThread.java:8167)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:496)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1100)
Caused by: java.lang.NullPointerException: 
  at com.tanguyantoine.react.MusicControlNotification$NotificationService.onStartCommand (MusicControlNotification.java:248)
  at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:4534)
  1. Platform ?

    • iOS
    • Android
  1. Device
  • Simulator
  • Real device

Make sure you have set foreground service enabled in manifest file

also make sure that if you are calling reset or stop control function then it should only be called if any control is set to enable
if any control is not enabled and reset/stop function is called then in that scenarios u may face this error

Foreground service is already enabled. Control is already enabled/running before stopping but null exceptions are still found.
Either way, is it better to catch null exceptions like not enabled objects should not trigger stopped/reset instead?

try to Enable controls only when needed. make sure that after setnowplaying is called then only u should enable controls.
Also try to go ahead with try catch

Some of these null pointer exceptions are coming from these lines where null is checked and then init() is called on null:

Thank you. Will be fixed in #351 release