Bug? Attempt to read from field 'anywheresoftware.b4a.BA anywheresoftware.b4a.BA.processBA' on a null obj

Alessandro71

Well-Known Member
Licensed User
Longtime User
i'm getting the following error

~i:** Activity (main) Resume **
Resuming Main Activity
Finished resuming Main Activity
~e:util_vvvvvvvvvvvvvv6 (java line: 213)
~e:java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.BA anywheresoftware.b4a.BA.processBA' on a null object reference
~e: at priusfan.info.bthsd10.util._vvvvvvvvvvvvvv6(util.java:213)
~e: at priusfan.info.bthsd10.main._refreshfast(main.java:3546)
~e: at java.lang.reflect.Method.invoke(Native Method)
~e: at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
~e: at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1038)
~e: at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:985)
~e: at priusfan.info.bthsd10.scanner._send_nextcmd(scanner.java:2439)
~e: at priusfan.info.bthsd10.scanner._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv0(scanner.java:1185)
~e: at priusfan.info.bthsd10.scanner._astream_newdata(scanner.java:1057)
~e: at java.lang.reflect.Method.invoke(Native Method)
~e: at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
~e: at anywheresoftware.b4a.BA$2.run(BA.java:360)
~e: at android.os.Handler.handleCallback(Handler.java:789)
~e: at android.os.Handler.dispatchMessage(Handler.java:98)
~e: at android.os.Looper.loop(Looper.java:164)
~e: at android.app.ActivityThread.main(ActivityThread.java:6809)
~e: at java.lang.reflect.Method.invoke(Native Method)
~e: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
~e: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

from a background service i'm using CallSub to call a sub in the Main activity that changes some labels
i'm actually checking if the activity is paused or not

B4X:
If Not(IsPaused(Main)) Then
    CallSub(Main, "RefreshFast")
End If

but, based on user's feedback, it happening when app is paused or resumed
inside RefreshFast, i'm also checking again if activity is paused, and all other code is in a Try/Catch block

B4X:
Public Sub RefreshFast
    If (IsPaused(Me)) Then
        Logger.WriteDebugLog("RefreshFast called while paused")
        Return
    End If
   
    Try
        Lbl_PIceText.Text = FormatPower(CarStatus.ICEPower)
        Lbl_PHVText.Text = FormatPower(CarStatus.HVPower)

        'more code...

    Catch
        util.HandleException("RefreshFast", util.EXCEPTION_CRITICAL)
    End Try
End Sub

exception is raised inside HandleException, where i'm trying to validate LastException in every conceivable way:

B4X:
Public Sub HandleException(subName As String, critical As Boolean)
    Private last As Exception
    Private validException = False As Boolean
    Try
        last = LastException
        validException = True
    Catch
        'got a null pointer accessing LastException from here
        Logger.WriteDebugLog("HandleException from " & subName)
    End Try
   
    If (validException) Then
        If (last.IsInitialized) Then
            Logger.WriteDebugLog(subName & ": " & last)
           
            If (critical) Then
                Starter.mCR.GenerateReport(last, "This is an exception from " & subName)
            End If
        End If
    End If
End Sub

here's also java code with the line generating the null pointer exception

B4X:
       catch (Exception e7) {
            (_ba.processBA == null ? _ba : _ba.processBA).setLastException(e7); //BA.debugLineNum = 236;BA.debugLine="Logger.WriteDebugLog(\"HandleException from \" & s";
mostCurrent._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv0._vvvvvvvvvvvvv4(_ba,"HandleException from "+_subname);
 };
 

Alessandro71

Well-Known Member
Licensed User
Longtime User
i'm not able to reproduce it in my environment
i'm collecting logs from users
i see it happening just after main activity resume, but according to users feedback, it happens when the app is in the background (i.e.: receiving a phone call, but please note that my app is not phone related, just think of it like a real time data collector)
 
Top