Android Question App crashes in release but not in debug on some phones.

coldtech

Member
Licensed User
Longtime User
I have an app that was working for quite some time now. I have a simple activity that retrieves JSON and stuffs it into a B4XTable.

I am running thru B4A-Bridge to try and troubleshoot this.

On my SM-G998U all works as expected regardless of how the project is compiled.

On a SM-A125U running in Debug mode everything works as expected but in Release mode when I open this activity it crashes with the following:

Logger connected to: samsung SM-A125U
b4xfloattextfield_settext (java line: 536)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String anywheresoftware.b4a.objects.B4XViewWrapper.getText()' on a null object reference
at coldtech.ctx.b4xfloattextfield._settext(b4xfloattextfield.java:536)
at coldtech.ctx.listhandler._onload(listhandler.java:1859)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1178)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8653)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

Perhaps someone can offer some ideas?
 

Gandalf

Member
Licensed User
Longtime User
Just a guess: debug mode is a bit slower than release. If you have async methods in your code or libraries, some variable or object may not be initialized in time they are used in release mode. Try adding Sleep(200) before operations you suspect to fail. If this helps, adjust the interval later. Try-Catch with Toast messages can also help to locate the fault point.
 
Upvote 0

coldtech

Member
Licensed User
Longtime User
The error happens in listhandler.onload where you are trying to set the text of an uninitialized B4XFloatTextField.

This is all that I can say. You can check whether the view IsInitialized before setting the text.
I narrowed it down some. In my OnLoad method I have:

B4XTable1.SearchField.Text = ""
B4XTable1.SearchField.Update

Removing those eliminated the above error but then I started getting a MDBottomAppBar exception, which I solved by checking if it is initialized and performing a sleep as Gandalf recommended.

Odd this cropped up after so long.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…