Bug? Crash when looking at view tags

App Dude

Active Member
Licensed User
Longtime User
To make changing UI colors easier, I've set tags on some (not all) views on a screen, and using those to set the colors in code.

B4X:
Private Sub SetupUIColors_MainPage
    For Each v As B4XView In Root.GetAllViewsRecursive
           Log(v)
        If v <> Null Then
            If v.Tag = "BG0" Then                             ' THIS IS LINE 643 IN THE CRASH DUMP
                v.Color = Colors.ARGB(0xFF, 14, 10, 8)
            Else if v.Tag = "BG1" Then
                v.Color = Colors.ARGB(0xFF, 35, 28, 25)
            Else if v.Tag = "BG2" Then
                v.Color = Colors.ARGB(0xFF, 44, 40, 38)
            Else if v.Tag = "T0" Then
                v.TextColor = Colors.ARGB(0xFF, 0xFF, 0xFF, 0xFF)
            Else if v.Tag = "T1" Then
    '            v.TextColor = Colors.ARGB(0xFF, 96, 255, 187)
                v.TextColor = Colors.ARGB(0xFF, 255, 255, 255)
            End If
        End If
    Next
End Sub


But *sometimes* (though not always), the app crashes when it gets to the first test (I've identified line 643 above, which is where the crash occurs). The java log dump from the crash seemed to indicate a null pointer issue, so I put the check for null, but it doesn't change...

Crash dump:
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(TextView) android.widget.TextView{f4e8450 V.ED..... ......ID 0,0-0,0 #3}
(MyScrollView) anywheresoftware.b4a.objects.ScrollViewWrapper$MyScrollView{4abe88b VFED.V... ......I. 0,0-0,0 #4}
(BALayout) anywheresoftware.b4a.BALayout{920d8c9 V.E...... ......ID 0,0-0,0}
Error occurred on line: 643 (B4XMainPage)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1055)
    at PiPi.eta.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:1064)
    at PiPi.eta.b4xpagesmanager._showpage(b4xpagesmanager.java:421)
    at PiPi.eta.b4xpagesmanager._addpage(b4xpagesmanager.java:249)
    at PiPi.eta.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:263)
    at PiPi.eta.b4xpagesmanager._initialize(b4xpagesmanager.java:169)
    at PiPi.eta.main._activity_create(main.java:589)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at PiPi.eta.main.afterFirstLayout(main.java:105)
    at PiPi.eta.main.access$000(main.java:17)
    at PiPi.eta.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:215)
    at android.app.ActivityThread.main(ActivityThread.java:6939)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:336)
    at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
    ... 24 more
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
    ... 25 more
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
    at PiPi.eta.b4xmainpage._setupuicolors_mainpage(b4xmainpage.java:765)
    at PiPi.eta.b4xmainpage._b4xpage_created(b4xmainpage.java:656)
    ... 27 more
** Activity (main) Resume **

I said "sometimes", because occasionally it won't crash. It seems like the crash occurs after if finds a BALayout view, but I'm not sure how to show more specifics of that view to better identify what and why it's doing this? Not sure if I'm missing something here, or if it's a bug.
Either way, is there a workaround to this?

Thanks.
 

App Dude

Active Member
Licensed User
Longtime User
This is what I get when it doesn't crash, in case it helps identify what could be causing the issue...

B4X:
** Service (starter) Start **
Service started in foreground mode.
** Activity (main) Create, isFirst = true **
(TextView) android.widget.TextView{1487b4e V.ED..... ......ID 0,0-0,0 #3}
(MyScrollView) anywheresoftware.b4a.objects.ScrollViewWrapper$MyScrollView{6381581 VFED.V... ......I. 0,0-0,0 #4}
(BALayout) anywheresoftware.b4a.BALayout{5efeaef V.E...... ......ID 0,0-0,0}
(BALayout) anywheresoftware.b4a.BALayout{41a5796 V.E...... ......ID 0,0-0,0 #5}
(BALayout) anywheresoftware.b4a.BALayout{1a4bae9 V.E...... ......I. 0,0-0,0 #6}
(BALayout) anywheresoftware.b4a.BALayout{21a182b V.E...... ......I. 0,0-0,0 #7}
(BALayout) anywheresoftware.b4a.BALayout{1ab3b5d V.E...... ......I. 0,0-0,0 #8}
(BALayout) anywheresoftware.b4a.BALayout{dc474ff V.E...... ......I. 0,0-0,0 #9}
(BALayout) anywheresoftware.b4a.BALayout{21b9191 V.E...... ......I. 0,0-0,0 #a}
(BALayout) anywheresoftware.b4a.BALayout{903f993 V.E...... ......I. 0,0-0,0 #b}
(BALayout) anywheresoftware.b4a.BALayout{421d185 V.E...... ......I. 0,0-0,0 #c}
(TextView) android.widget.TextView{28419e7 V.ED..... ......ID 0,0-0,0 #d}
(TextView) android.widget.TextView{edcf39 V.ED..... ......ID 0,0-0,0 #e}
(TextView) android.widget.TextView{ad609fb V.ED..... ......ID 0,0-0,0 #f}
(TextView) android.widget.TextView{e671ead V.ED..... ......ID 0,0-0,0 #10}
(TextView) android.widget.TextView{384bdcf V.ED..... ......ID 0,0-0,0 #11}
(TextView) android.widget.TextView{5a113e1 V.ED..... ......ID 0,0-0,0 #12}
(BALayout) anywheresoftware.b4a.BALayout{1e8e963 V.E...... ......ID 0,0-0,0}
(B4ASpinner) anywheresoftware.b4a.objects.SpinnerWrapper$B4ASpinner{49609fc V.ED..CL. ......I. 0,0-0,0 #2c}
(TextView) android.widget.TextView{f0ec2d5 GF.D..C.. ......ID 0,0-0,0 #13}
(Button) android.widget.Button{9bd00b7 VFED..C.. ......I. 0,0-0,0 #14}
(TextView) android.widget.TextView{876ff89 V.ED..... ......ID 0,0-0,0 #15}
(TextView) android.widget.TextView{37137cb V.ED..... ......ID 0,0-0,0 #16}
(EditText) android.widget.EditText{8a85dfd VFED..CL. ......I. 0,0-0,0 #17}
(EditText) android.widget.EditText{b1a4fb5 VFED..CL. ......I. 0,0-0,0 #18}
(TextView) android.widget.TextView{e592697 V.ED..... ......ID 0,0-0,0 #19}
(Button) android.widget.Button{1b6f669 VF.D..C.. ......I. 0,0-0,0 #1a}
(TextView) android.widget.TextView{80e77ab VFED..C.. ......ID 0,0-0,0 #1b}
(BALayout) anywheresoftware.b4a.BALayout{ad09edd V.E...... ......ID 0,0-0,0}
(B4ASpinner) anywheresoftware.b4a.objects.SpinnerWrapper$B4ASpinner{fd53885 V.ED..CL. ......I. 0,0-0,0 #2d}
(BALayout) anywheresoftware.b4a.BALayout{9f2bc7f V.E...... ......ID 0,0-0,0}
(B4ASpinner) anywheresoftware.b4a.objects.SpinnerWrapper$B4ASpinner{dfc6da V.ED..CL. ......I. 0,0-0,0 #2e}
(TextView) android.widget.TextView{76b9d11 V.ED..... ......ID 0,0-0,0 #1c}
(TextView) android.widget.TextView{9c7a913 V.ED..... ......ID 0,0-0,0 #1d}
(BALayout) anywheresoftware.b4a.BALayout{51c0505 V.E...... ......ID 0,0-0,0}
(B4ASpinner) anywheresoftware.b4a.objects.SpinnerWrapper$B4ASpinner{47a470b V.ED..CL. ......I. 0,0-0,0 #2f}
(TextView) android.widget.TextView{f60b167 V.ED..... ......ID 0,0-0,0 #1e}
(BALayout) anywheresoftware.b4a.BALayout{cf9aab9 V.E...... ......ID 0,0-0,0}
(B4ASpinner) anywheresoftware.b4a.objects.SpinnerWrapper$B4ASpinner{737c9e8 V.ED..CL. ......I. 0,0-0,0 #30}
(BALayout) anywheresoftware.b4a.BALayout{bf7097b V.E...... ......ID 0,0-0,0}
(B4ASpinner) anywheresoftware.b4a.objects.SpinnerWrapper$B4ASpinner{3b5d801 V.ED..CL. ......I. 0,0-0,0 #31}
(BALayout) anywheresoftware.b4a.BALayout{54222d V.E...... ......ID 0,0-0,0}
(B4ASpinner) anywheresoftware.b4a.objects.SpinnerWrapper$B4ASpinner{e0376a6 V.ED..CL. ......I. 0,0-0,0 #32}
(BALayout) anywheresoftware.b4a.BALayout{13da54f V.E...... ......ID 0,0-0,0}
(B4ASpinner) anywheresoftware.b4a.objects.SpinnerWrapper$B4ASpinner{448e7 V.ED..CL. ......I. 0,0-0,0 #33}
(TextView) android.widget.TextView{726bf61 V.ED..... ......ID 0,0-0,0 #1f}
(EditText) android.widget.EditText{c3538e3 VFED..CL. ......I. 0,0-0,0 #20}
(TextView) android.widget.TextView{44c9655 V.ED..... ......ID 0,0-0,0 #21}
(EditText) android.widget.EditText{7c03837 VFED..CL. ......I. 0,0-0,0 #22}
(TextView) android.widget.TextView{3747b09 V.ED..... ......ID 0,0-0,0 #23}
(TextView) android.widget.TextView{af6d74b V.ED..... ......ID 0,0-0,0 #24}
(TextView) android.widget.TextView{4d5017d V.ED..... ......ID 0,0-0,0 #25}
(TextView) android.widget.TextView{73b0a1f V.ED..... ......ID 0,0-0,0 #26}
(BALayout) anywheresoftware.b4a.BALayout{aa07db1 V.E...... ......ID 0,0-0,0}
(ImageView) android.widget.ImageView{9b39c94 V.ED..... ......I. 0,0-0,0 #35}
(BALayout) anywheresoftware.b4a.BALayout{9a6f33d VFE...C.. ......I. 0,0-0,0 #34}
(TextView) android.widget.TextView{a0c84b3 V.ED..... ......ID 0,0-0,0 #27}
(TextView) android.widget.TextView{c3903a5 V.ED..... ......ID 0,0-0,0 #28}
(BALayout) anywheresoftware.b4a.BALayout{69cbb07 V.E...... ......ID 0,0-0,0}
(ImageView) android.widget.ImageView{8605732 V.ED..... ......I. 0,0-0,0 #37}
(BALayout) anywheresoftware.b4a.BALayout{e428c83 VFE...C.. ......I. 0,0-0,0 #36}
(TextView) android.widget.TextView{3246759 V.ED..... ......ID 0,0-0,0 #29}
(TextView) android.widget.TextView{b22e11b V.ED..... ......ID 0,0-0,0 #2a}
(TextView) android.widget.TextView{5c03ccd V.ED..... ......ID 0,0-0,0 #2b}
 

App Dude

Active Member
Licensed User
Longtime User
Very unlikely to be a bug, more likely to be where and when you are calling SetupUIColors_MainPage but you haven't shown us that :(

I'm doing that in B4XPage_Created...


B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    B4XPages.SetTitle(Me, "App Title")

    svScn1.Top = 50dip
    svScn1.Left = 0dip
    svScn1.Width = 100%x
    svScn1.Height = 100%y-50dip
    svScn1.GetView(0).LoadLayout("Screen1Panel")
    Panel1.Left = 0dip
    Panel1.Width = 100%x
    Panel1.Top = 0dip
    Panel1.Height = 800dip
    Panel1.Color = Colors.Black
    swTimeFormat.mBase.Left = 90dip
    swTimeFormat.mBase.Width = 70dip
    lblTimeFormat12.Left = 30dip
    lblTimeFormat12.Width = 60dip
    lblTimeFormat24.Left = 160dip
    lblTimeFormat24.Width = 50dip

    SetupUIColors_MainPage
        
        ...
 

App Dude

Active Member
Licensed User
Longtime User
You are changing the color of all views docked to that panel. One or more are scrollviews and you cannot change the color of textColor in a scrollView.

Try to verify that the V variable is Label or EditText

Which parameter would have the info (Label or EditText)? I'm not seeing a parameter for "v" that would let me identify the type.
 

BlueVision

Active Member
Licensed User
Longtime User
Some months ago I ran into a similiar problem, not seeing the wood for trees.
I solved MY mistake (and it was my programming mistake) by doing a readout of the tags and printing a LOG-line with its values before I used the tag's for further computing.
Then step slowly line by line through the code and see what happens...

This sounds like a stupid teaching advice. But believe me, you will solve the problem in this way, everything will be clear immediately when you realize what went wrong.
 

App Dude

Active Member
Licensed User
Longtime User
Some months ago I ran into a similiar problem, not seeing the wood for trees.
I solved MY mistake (and it was my programming mistake) by doing a readout of the tags and printing a LOG-line with its values before I used the tag's for further computing.
Then step slowly line by line through the code and see what happens...

This sounds like a stupid teaching advice. But believe me, you will solve the problem in this way, everything will be clear immediately when you realize what went wrong.

I'm trying to do that now, but I haven't figured out (yet) how to show the information for a view. There's not parameter with name, ID, type, etc.
 

App Dude

Active Member
Licensed User
Longtime User
You are changing the color of all views docked to that panel. One or more are scrollviews and you cannot change the color of textColor in a scrollView.

Try to verify that the V variable is Label or EditText

There's only one scrollview and it has a parameter to set a tag (in the designer). But I don't have a tag. So it should not crash when comparing the tag.
 

Serge Bertet

Active Member
Licensed User
Try
If "BG0" == v.Tag Then
instead of
If v.Tag == "BG0" Then

... maybe.
I sometime receive an advice from IDE doing this way.
 
Top