Hello everyone, I'm trying to get all views in a tabstrip
I am getting a null return, using the code below.
B4X:
Private Sub getFieldsInfo(findtag As String) As String
Dim lbl As Label
For Each v As View In Panel1.GetAllViewsRecursive ' txtAccntNum
If v Is Label Then
lbl = v
If v.tag = findtag Then
Log(v.tag)
Dim mdata As String
mdata = lbl.Text
Log(mdata)
Return mdata
End If
End If
Next
Return False
End Sub
I think because you are mixing between "v" and "label".
After assigning "v" to "lbl" you should refer only to "lbl".
Try this
B4X:
Private Sub getFieldsInfo(findtag As String) As String
For Each v As View In Panel1.GetAllViewsRecursive ' txtAccntNum
If v Is Label Then
Dim lbl as Label
lbl = v
If lbl.tag = findtag Then
Log(lbl.tag)
Dim mdata As String
mdata = lbl.Text
Log(mdata)
Return mdata
End If
End If
Next
Return False
End Sub
I think because you are mixing between "v" and "label".
After assigning "v" to "lbl" you should refer only to "lbl".
Try this
B4X:
Private Sub getFieldsInfo(findtag As String) As String
For Each v As View In Panel1.GetAllViewsRecursive ' txtAccntNum
If v Is Label Then
Dim lbl as Label
lbl = v
If lbl.tag = findtag Then
Log(lbl.tag)
Dim mdata As String
mdata = lbl.Text
Log(mdata)
Return mdata
End If
End If
Next
Return False
End Sub
Logger connected to: 055542508O000936
--------- beginning of crash
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
main_getfieldsinfo (java line: 410)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
at b4a.example.main._getfieldsinfo(main.java:410)
at b4a.example.main._mnu1_click(main.java:446)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA$1.run(BA.java:360)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:264)
at android.app.ActivityThread.main(ActivityThread.java:7581)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
Thank you for the time, but unfortunately, I still have the same error:
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
main_getfieldsinfo (java line: 410)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
at b4a.example.main._getfieldsinfo(main.java:410)
at b4a.example.main._mnu1_click(main.java:446)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA$1.run(BA.java:360)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:264)
at android.app.ActivityThread.main(ActivityThread.java:7581)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
I am not used to TabStrip so I could not have done the best/correct method.
Your issue was that you have Panel1 as base panel in all pages.
Using Panel1 as target it will reference the last one added, so Page 3.
I renamed the panels on the 3 pages as Panel1, Panel2, Panel3.
Then I declared another panel, currentpanel, that will reference the right one when changing page.
Check the code.