Android Question how do you DEBUG - how to DEBUG

vangogh

Active Member
Licensed User
Longtime User
look this
---
Sub btnMyButton_Click

Dim test As Int

test="hello" 'this causaes an error

end sub
----

--- in RELEASE mode:

this make the app crash, WITHOUT any error code, without error line, nothing. it closes.

it's VERY HARD for me to debug "run time" my app, when the user says "the program closed, I don't know what I was doing EXACTLY - I got no error"

older versions of b4a (i had 2.71) had a POWERFUL debugging system, see the image what I got when an error arises


--- in DEBUG mode, with legacy debugger enabled

YES! I get the error, the reason, the line number, the sub involved... YES! (see the -example- attached image, regarding another example error)
very easy to fix the issue!

... but then, in DEBUG mode, if I close the developing ide (I give the apk to the final user), the app crashes immediately after I launch it. immediately. also if there is no error.


I use and OPPO device with android 13
I use "legacy debugger" option - it's VERY useful - if not, the app simply crash. unuseful. legacy debugger is an absolute MUST
... but it doesn't work on release mode, and release mode seems to be mandatory if the b4a IDE is not there

so. What am I missing? HOW to see what error my final user get?


attached, a debug error I saw on b4a version2
thank you
 

Attachments

  • errore debug b4a 2.jpeg
    errore debug b4a 2.jpeg
    151.4 KB · Views: 139

Spavlyuk

Active Member
Licensed User
 
Upvote 0

vangogh

Active Member
Licensed User
Longtime User
I read about the
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean

Thank you!

I will try it, but I miss the line number and the sub where the err arised...
a solution would be being able to install the app in "bebug mode" to the final user. Here i can find all I need as I set the "legacy debug" on
I did this way till "yesterday" without any issue and with great advantages
now my app in debug mode closes immediately if the IDE is not connected (b4a bridge)

am I doing something wrong? Can I give to the final user that "result_debug.apk" version that would solve my needs?

thank you
 
Upvote 0

Spavlyuk

Active Member
Licensed User
I don't think you can (or should) send the debug version. You can perhaps try removing the Application_Error sub and see if the old behavior returns.
If there is a sub named Application_Error in the Starter service module then the default error dialog will never appear.
Note that the starter service template includes this sub. It is recommended to include this sub in all projects.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
No, the old behaviour in legacy debug mode inserted debug code into the app for every line of B4X code, so that is how it knew where the code failed. The normal debug does not do this as the majority of code is actually running on the PC in the IDE and only a shell app is running on the device.

Without the IDE connected the only way to trap an exception is, as stated above, with Sub Application_Error in release mode. However you cannot show a MsgBox in the service so you need to call a Sub in an Activity to do so. From the stack trace you should be able to see the Sub and Java line number in error. You can look at the generated Java code in Objects/src/... to find the Java line which should have the B4A code line above it.
In the Starter service:
'
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return CallSub3("Main", "ShowError", Error, StackTrace)   
End Sub
In Main activity:
' You must return False so Android will not kill the app when it returns from MsgboxAsync
' and so let the Msgbox stay displayed
Public Sub ShowError (Error As Exception, StackTrace As String) As Boolean
    MsgboxAsync(StackTrace, Error)
    Return False
End Sub
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I tried to replicate that error in a minimal app (assign a string to an INT).
In Release, connected to the IDE, I get the Sub that throw the error and even a description of the error.
Then it can be not immediate to find it in the code, but there is an indication of it.
This is what I get in Release
main_button1_click (java line: 370)
java.lang.NumberFormatException: For input string: "Hello"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at b4a.example.main._button1_click(main.java:370)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7448)
at android.view.View.performClickInternal(View.java:7425)
at android.view.View.access$3600(View.java:810)
at android.view.View$PerformClick.run(View.java:28305)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
If it can be of any help, I usually use the Debug USB connected directly by cable after enabling it in the Developer Options of the device.
Without B4A-Bridge.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
use the Debug USB connected directly by cable after enabling it in the Developer Options of the device.
Without B4A-Bridge
Exactly what I suggested in the OP wish thread!
 
Upvote 0

vangogh

Active Member
Licensed User
Longtime User
I tried to replicate that error in a minimal app (assign a string to an INT).
In Release, connected to the IDE, I get the Sub that throw the error and even a description of the error.
Then it can be not immediate to find it in the code, but there is an indication of it.
This is what I get in Release

If it can be of any help, I usually use the Debug USB connected directly by cable after enabling it in the Developer Options of the device.
Without B4A-Bridge.

yes. I did it in the same way now.
it works, but you can understand how easier was to have a message like

Error in sub thisismysub
line 1234
a = "hello"
string to integer error.

looking at the screenshot (sent by what's app form the final user, 1000miles away from me) I could fix the issue 30 seconds
Thank you
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I think I missed that period or that Debug Mode.
Of course it would be easier to have a direct indication of what is happened.
It looks strange to me that we lost such a functionality.
Question is:
was it OS dependant or B4A dependant?
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
When APK is executing in Release Mode it's Java Code.
It's not anymore B4A code.
So how should it be possible to get the line number?
Probably I wrote something stupid.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
When APK is executing in Release Mode it's Java Code.
It's not anymore B4A code.
So how should it be possible to get the line number?
Probably I wrote something stupid.
The "very old" debugger introduced additional code to the release compilation app, so I guess the the Java subs were somehow cross-linked to the b4a code
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I began my B4A adventure with version 6.80 if I remember correctly.
So probably I am totally out of this thing.
I didn't understood everything correctly from the beginning.
 
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
I understand the problem, but I don't know this old B4A version. At the end of the day, we have to move with the times and not hold on to things that no longer exist. I am sure that in the further development of B4A there were good and serious reasons to finally abandon this concept. I think that today's complexity of the development environment simply cannot support this feature any more. It reminds me a lot of old interpreter versions of BASIC...

So you have to live with what you have available. What remains? There is at least the possibility to create some kind of logfile in parallel while the app is running. At least the executed subroutines and important variables could be noted there, which could then be helpful in the event of an error.
You can also try to catch incorrect entries from the very beginning and then point them out to the user. It is a question of the complexity of the programme. TRY/CATCH/ENDTRY can also be very helpful.
In the example at hand (and I think it is, to give us an idea of what you want), this may also be a logical programming error from the start. In my opinion, if the user has to enter an integer value at the appropriate place, this value must also be checked by the programme for correctness.
But I know just as well that some errors are very difficult to find in this way.
Sometimes a programme crashes simply because a variable takes on a value that the programmer would never have expected.
The best way is to secure one's programme accordingly against erroneous entries by a user in this specific case.
There is a saying in my mother tongue:

Idiots are inventive

Edit:
In this special case I would simply specify the input field as a "number" field. So there is no chance to put a character into the field. Or simply show a keyboard with numbers. Guiding the user and using the possibilies we have...
 
Last edited:
Upvote 0

vangogh

Active Member
Licensed User
Longtime User
When APK is executing in Release Mode it's Java Code.
It's not anymore B4A code.
So how should it be possible to get the line number?
Probably I wrote something stupid.
no, not stupid.
let me explain
in oldest versions, the compiler ADDED some debug code as "the_following_line_of_code_is 'line: 1234 - original code: a = "hello"'
so, at least one "debug code line" for each line of code b4a translated in java.
when the java crashed, the java code dispayed the "the_following_line_of_code_is" content

it was GENIAL.

And terribly useful. I fixed easily so many issues...

saaaadly, it has been removed.
oh, well, it wworks like it did, but only in debug mode, and the debug mode cannot be given to the end user anymore. it was.
Sagenut, hope i explained better, now.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
no, not stupid.
let me explain
in oldest versions, the compiler ADDED some debug code as "the_following_line_of_code_is 'line: 1234 - original code: a = "hello"'
so, at least one "debug code line" for each line of code b4a translated in java.
when the java crashed, the java code dispayed the "the_following_line_of_code_is" content

it was GENIAL.

And terribly useful. I fixed easily so many issues...

saaaadly, it has been removed.
oh, well, it wworks like it did, but only in debug mode, and the debug mode cannot be given to the end user anymore. it was.
Sagenut, hope i explained better, now.
Now everything it's clear.
Thanks
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
What would be nice is B4X to produce a 2nd file on Release compile.
In that file is a cross refrence of line 2000 (or what ever from the Java code) is line 855 (or at least get us close) in the B4X code. Sort of like the PBD in .NET
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
That information is in the compiled *.java files in the folder under Objects/src/. It would be fairly trivial to write a utility that iterated those folders and produce the file you suggest, or you could just look in those files yourself when needed.
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
That information is in the compiled *.java files in the folder under Objects/src/. It would be fairly trivial to write a utility that iterated those folders and produce the file you suggest, or you could just look in those files yourself when needed.
As i use a BAT file to do my release builds I already ZIP up the Objects/Src folder and keep it.
An option in the IDE would be ideal.
 
Upvote 0
Top