LucaMs Expert Licensed User Longtime User Jul 7, 2018 #1 I "set" immersive mode for the Main; from here I start another Activity and Activity_WindowFocusChanged causes a crash if I start the app in debug mode (see the test project attached). Spoiler: Error Msg Copying updated assets files (1) *** Service (starter) Create *** ** Service (starter) Start ** ** Activity (main) Create, isFirst = true ** ** Activity (main) Resume ** ** Activity (main) Pause, UserClosed = false ** Error occurred on line: 44 (Main) java.lang.NullPointerException at b4a.example.main._activity_windowfocuschanged(main.java:427) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144) at b4a.example.main.onWindowFocusChanged(main.java:185) at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2678) at android.view.View.dispatchWindowFocusChanged(View.java:8018) at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:968) at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3289) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:149) at android.app.ActivityThread.main(ActivityThread.java:5257) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610) at dalvik.system.NativeStart.main(Native Method) Tested only on an Android 4.4.2. Attachments ImmveModeTest.zip ImmveModeTest.zip 9.9 KB · Views: 548 Last edited: Jul 7, 2018
I "set" immersive mode for the Main; from here I start another Activity and Activity_WindowFocusChanged causes a crash if I start the app in debug mode (see the test project attached). Spoiler: Error Msg Copying updated assets files (1) *** Service (starter) Create *** ** Service (starter) Start ** ** Activity (main) Create, isFirst = true ** ** Activity (main) Resume ** ** Activity (main) Pause, UserClosed = false ** Error occurred on line: 44 (Main) java.lang.NullPointerException at b4a.example.main._activity_windowfocuschanged(main.java:427) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144) at b4a.example.main.onWindowFocusChanged(main.java:185) at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2678) at android.view.View.dispatchWindowFocusChanged(View.java:8018) at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:968) at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3289) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:149) at android.app.ActivityThread.main(ActivityThread.java:5257) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610) at dalvik.system.NativeStart.main(Native Method) Tested only on an Android 4.4.2.
LucaMs Expert Licensed User Longtime User Jul 7, 2018 #2 In the test project attached to the first post, it seems you can solve by changing Sleep(300) to Sleep(100): Code: Sub Activity_WindowFocusChanged(HasFocus As Boolean) If HasFocus Then Try Dim jo As JavaObject = Activity Sleep(100) jo.RunMethod("setSystemUiVisibility", Array As Object(5894)) '3846 - non-sticky Catch Log(LastException) End Try End If End Sub but in other projects this change does not solve. Upvote 0
In the test project attached to the first post, it seems you can solve by changing Sleep(300) to Sleep(100): Code: Sub Activity_WindowFocusChanged(HasFocus As Boolean) If HasFocus Then Try Dim jo As JavaObject = Activity Sleep(100) jo.RunMethod("setSystemUiVisibility", Array As Object(5894)) '3846 - non-sticky Catch Log(LastException) End Try End If End Sub but in other projects this change does not solve.
D Deleted member 103 Guest Jul 7, 2018 #3 Did you read that from Erel? he code was updated with a small change. The Log(LastException) line was commented. The Activity_WindowFocusChanged event can fire after the activity was paused and this line can cause an untrapped exception to be raised. Click to expand... I tried it with the tip of Erel and it works. Upvote 0
Did you read that from Erel? he code was updated with a small change. The Log(LastException) line was commented. The Activity_WindowFocusChanged event can fire after the activity was paused and this line can cause an untrapped exception to be raised. Click to expand... I tried it with the tip of Erel and it works.
LucaMs Expert Licensed User Longtime User Jul 7, 2018 #4 Filippo said: Did you read that from Erel? I tried it with the tip of Erel and it works. Click to expand... I had read that quickly and I had assumed that the code had been "fixed". My project crashes even commenting that line. Upvote 0
Filippo said: Did you read that from Erel? I tried it with the tip of Erel and it works. Click to expand... I had read that quickly and I had assumed that the code had been "fixed". My project crashes even commenting that line.
LucaMs Expert Licensed User Longtime User Jul 7, 2018 #5 LucaMs said: My project crashes even commenting that line. Click to expand... ... but commenting that line and setting again Sleep to 300 it's ok Upvote 0
LucaMs said: My project crashes even commenting that line. Click to expand... ... but commenting that line and setting again Sleep to 300 it's ok
Erel B4X founder Staff member Licensed User Longtime User Jul 8, 2018 #7 Can you post the logs after you commented the relevant line? Upvote 0
LucaMs Expert Licensed User Longtime User Jul 8, 2018 #8 Sometimes the error happens when I write nothing in the Catch part; so I write a Sleep there but... sometimes Sleep(100) is not enough, I have to increase the time, sometimes it is the opposite, I have to decrease this value. Going by trial: sometimes it can be solved by "cleaning" the project (CTRL+P), other times stopping the project using the device settings. Erel said: Can you post the logs after you commented the relevant line? Click to expand... Spoiler: Error msg ** Activity (main) Pause, UserClosed = false ** Error occurred on line: 393 (Main) java.lang.NullPointerException at mbnt.MyProjName.it.main._activity_windowfocuschanged(main.java:695) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144) at mbnt.MyProjName.it.main.onWindowFocusChanged(main.java:185) at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2678) at android.view.View.dispatchWindowFocusChanged(View.java:8018) at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:968) at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3289) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:149) at android.app.ActivityThread.main(ActivityThread.java:5257) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610) at dalvik.system.NativeStart.main(Native Method) Upvote 0
Sometimes the error happens when I write nothing in the Catch part; so I write a Sleep there but... sometimes Sleep(100) is not enough, I have to increase the time, sometimes it is the opposite, I have to decrease this value. Going by trial: sometimes it can be solved by "cleaning" the project (CTRL+P), other times stopping the project using the device settings. Erel said: Can you post the logs after you commented the relevant line? Click to expand... Spoiler: Error msg ** Activity (main) Pause, UserClosed = false ** Error occurred on line: 393 (Main) java.lang.NullPointerException at mbnt.MyProjName.it.main._activity_windowfocuschanged(main.java:695) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144) at mbnt.MyProjName.it.main.onWindowFocusChanged(main.java:185) at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2678) at android.view.View.dispatchWindowFocusChanged(View.java:8018) at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:968) at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3289) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:149) at android.app.ActivityThread.main(ActivityThread.java:5257) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610) at dalvik.system.NativeStart.main(Native Method)
LucaMs Expert Licensed User Longtime User Jul 8, 2018 #9 To solve THIS TIME (previous post): tried both, cleaning and stopping the project, without success. I added sleep (100) and this solved (then I received the same error in another Activity, resolved in the same way). Upvote 0
To solve THIS TIME (previous post): tried both, cleaning and stopping the project, without success. I added sleep (100) and this solved (then I received the same error in another Activity, resolved in the same way).
LucaMs Expert Licensed User Longtime User Jul 17, 2018 #10 Well, MAYBE I found something "useful" (for Erel ). Catch block empty. Start B4A, open the project, run and you get the error. Change the Sleep command (it does not matter how many ms) inside the Activity_FocusChanged event routine and you no more get the error (in the same "b4a session"). Save the project changed, open and start it again... and again you get the error. Upvote 0
Well, MAYBE I found something "useful" (for Erel ). Catch block empty. Start B4A, open the project, run and you get the error. Change the Sleep command (it does not matter how many ms) inside the Activity_FocusChanged event routine and you no more get the error (in the same "b4a session"). Save the project changed, open and start it again... and again you get the error.