Android Question Rndom Error

pazzokli

Active Member
Licensed User
Longtime User
I, from a few days my app that should run 24/24 crash with this error in log

B4X:
Message data: {body=nuovo file nodi, title=NODI, mandante=0}
0:1665928320216860%f81d54e4f9fd7ecd
** Activity (main) Pause, UserClosed = false **
main$ResumableSub_Activity_WindowFocusChangedresume (java line: 1359)
java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.BA com.domos.servo.main.activityBA' on a null object reference
    at com.domos.servo.main$ResumableSub_Activity_WindowFocusChanged.resume(main.java:1359)
    at com.domos.servo.main._activity_windowfocuschanged(main.java:1288)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at com.domos.servo.main.onWindowFocusChanged(main.java:186)
    at com.android.internal.policy.DecorView.onWindowFocusChanged(DecorView.java:2156)
    at android.view.View.dispatchWindowFocusChanged(View.java:14657)
    at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:1498)
    at android.view.ViewRootImpl.handleWindowFocusChanged(ViewRootImpl.java:3455)
    at android.view.ViewRootImpl.access$1300(ViewRootImpl.java:205)
    at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:5358)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8107)
    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)
main$ResumableSub_Activity_WindowFocusChangedresume (java line: 1359)
java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.BA com.domos.servo.main.activityBA' on a null object reference
    at com.domos.servo.main$ResumableSub_Activity_WindowFocusChanged.resume(main.java:1359)
    at com.domos.servo.main._activity_windowfocuschanged(main.java:1288)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at com.domos.servo.main.onWindowFocusChanged(main.java:186)
    at com.android.internal.policy.DecorView.onWindowFocusChanged(DecorView.java:2156)
    at android.view.View.dispatchWindowFocusChanged(View.java:14657)
    at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:1498)
    at android.view.ViewRootImpl.handleWindowFocusChanged(ViewRootImpl.java:3455)
    at android.view.ViewRootImpl.access$1300(ViewRootImpl.java:205)
    at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:5358)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8107)
    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)

I cannot understand origin of crash
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Hard to say, but based on the error lines below, you are trying to access an object that doesn't exist anymore (or never did).
If you can replicate the error in debug mode, you get the line where that occurred.

Another hint is "Activity_WindowFocusChanged". Is this somewhere in your code?

B4X:
main$ResumableSub_Activity_WindowFocusChangedresume (java line: 1359)
java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.BA com.domos.servo.main.activityBA' on a null object reference

It looks like you will need to do some work to find out what happened and where.

The fact that it worked before, doesn't help much. It has been shown that in general, programs cannot be proven to be 100% correct.
Some condition occurred that never occurred before.
 
Last edited:
Upvote 0

pazzokli

Active Member
Licensed User
Longtime User
Hard to say, but based on the error lines below, you are trying to access an object that doesn't exist anymore (or never did).
If you can replicate the error in debug mode, you get the line where that occurred.

Another hint is "Activity_WindowFocusChanged". Is this somewhere in your code?

B4X:
main$ResumableSub_Activity_WindowFocusChangedresume (java line: 1359)
java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.BA com.domos.servo.main.activityBA' on a null object reference

It looks like you will need to do some work to find out what happened and where.

The fact that it worked before, doesn't help much. It has been shown that in general, programs cannot be proven to be 100% correct.
Some condition occurred that never occurred before.
Williams, thanks for your message.
In debug mode apps doesn't run.
Seems sometinghs related to notifications, but hard identify cause
 
Last edited:
Upvote 0

agraham

Expert
Licensed User
Longtime User
It looks like it is failing in your Resumable Sub, windowfocuschanged. It is failing as the Activity activityBA field it is accesssing contains a null pointer. This probably means the activity has been recreated but not yet fully instantiated as a valid activityBA is set during activity creation but I have no idea why the windowfocuschanged event would be called at this time. I would guess you have a timing/order of execution problem.
 
Upvote 0

pazzokli

Active Member
Licensed User
Longtime User
It looks like it is failing in your Resumable Sub, windowfocuschanged. It is failing as the Activity activityBA field it is accesssing contains a null pointer. This probably means the activity has been recreated but not yet fully instantiated as a valid activityBA is set during activity creation but I have no idea why the windowfocuschanged event would be called at this time. I would guess you have a timing/order of execution problem.

There is a sub called Activity_WindowFocusChanged
I copied it from an Erel example and needed for run app in full size
But I never change it from a couple of years

Activity_WindowFocusChanged:
Sub Activity_WindowFocusChanged(HasFocus As Boolean) 
    If HasFocus Then
        Try
            Dim jo As JavaObject = Activity
            Sleep(300)
            jo.RunMethod("setSystemUiVisibility", Array As Object(5894)) '3846 - non-sticky
        Catch
            Log(LastException)
        End Try
        
    End If
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
But I never change it from a couple of years
Well something has gone wrong! I've looked at the generated Java and the only place I can see in that event code that accesses activityBA is in the Log statement in the catch block. It is possible that an exception has occurred and a further uncaught one is raised by the Log statement. Remove the Try ..Catch and see what the log shows for any uncaught exception.
 
Upvote 0

pazzokli

Active Member
Licensed User
Longtime User
Well something has gone wrong! I've looked at the generated Java and the only place I can see in that event code that accesses activityBA is in the Log statement in the catch block. It is possible that an exception has occurred and a further uncaught one is raised by the Log statement. Remove the Try ..Catch and see what the log shows for any uncaught exception.
I'm going to try and say you something
When removed Try and Catch is possible I've to wait more than an hour. Sometime error appear after a few minute, sometime after some hours
 
Upvote 0

Spavlyuk

Active Member
Licensed User
Activity_WindowFocusChanged is somewhat of a special event. If you investigate the generated main.java code, you'll find that when the application is paused, mostCurrent is set to null. Activity_WindowFocusChanged can be called even if the application is paused, meaning you cannot access any of your variables during that time. The error may be getting triggered by the application resuming and pausing before the code below Sleep(300) is executed.

B4XPages is using a trick to disable pausing but I'm not sure if it's applicable in non-B4XPages. You might want to try it and see if it helps.

B4X:
Dim module As JavaObject
module.InitializeStatic(jo.RunMethodJO("getActivityBA", Null).GetField("className")).SetField("dontPause", True)
 
Last edited:
Upvote 0
Top