Android Question Error at startup : PowerManager$WakeLock.release on a null object reference

SDFP Studio

Member
Licensed User
Hello everyone,
I can't understand where an error that I have on some devices when starting the application, is coming from :rolleyes:

The error is ::
Exception java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.PowerManager$WakeLock.release()' on a null object reference
  at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.handleStartIntent (ServiceHelper.java:155)
  at sdfpstudio.abmusictrainer.notifs.handleStart (notifs.java:102)
  at sdfpstudio.abmusictrainer.notifs.access$000 (notifs.java:8)
  at sdfpstudio.abmusictrainer.notifs$2.run (notifs.java:83)
  at android.os.Handler.handleCallback (Handler.java:942)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:226)
  at android.os.Looper.loop (Looper.java:313)
  at android.app.ActivityThread.main (ActivityThread.java:8810)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:604)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)

My 'notifs'module:
#Region  Service Attributes
    #StartAtBoot: False
    
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Service_Create
    ' Nécessaire pour ne pas avoir une deuxième notif
    ' Service.StopAutomaticForeground
End Sub

Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.IsInitialized Then
        ' Notif visible seulement si app masquée
        Select Case StartingIntent.Action
            Case "ActionPlayPause"
            Case "ActionPrev"
            Case "ActionNext"
            Case "ActionRewind"
            Case "ActionForward"
            Case "ActionDelete"
        End Select
    End If
    ' Nécessaire pour ne pas avoir une deuxième notif
    ' Service.StopAutomaticForeground
End Sub

Sub Service_Destroy
    Service.StopAutomaticForeground
End Sub

I initially had Service.StopAutomaticForeground in Service_Create and at the end of Service_Start. I commented them with no change.
Keeped the one in Service_Destroy.
Not sure I well understood theses functions :(

Online error 102 is : anywheresoftware.b4a.objects.IntentWrapper ...

notifs.java:
    private void handleStart(android.content.Intent intent) {
        BA.LogInfo("** Service (notifs) Start **");
        java.lang.reflect.Method startEvent = processBA.htSubs.get("service_start");
        if (startEvent != null) {
            if (startEvent.getParameterTypes().length > 0) {
                anywheresoftware.b4a.objects.IntentWrapper iw = ServiceHelper.StarterHelper.handleStartIntent(intent, _service, processBA);
                processBA.raiseEvent(null, "service_start", iw);
            }
            else {
                processBA.raiseEvent(null, "service_start");
            }
        }
    }

Tell me if you need more code.
Thank you for your help ?
Have a nice day everyone

Francis
 

SDFP Studio

Member
Licensed User
Hello Erel
I do not start the service, when I init my nb6 notification I have some AddButtonAction() that receives the service as a parameter and It works like that.
 
Upvote 0
Top