iOS Question [SOLVED ?] - Copy and paste designer elements between B4A and B4I platforms

Sergio Haurat

Active Member
Licensed User
Longtime User
No matter which option I enter in the application, whenever it wants to load a new B4XPage in B4I, the execution breaks


*** frmxedituser: B4XPage_Created [mainpage]
Error occurred on line: 467 (AS_TextFieldAdvanced)
Target is null. Method called: _initialize:::

*** frmxfilter: B4XPage_Created [mainpage]
Error occurred on line: 53 (B4XComboBox)
Target is null. Method called: _initialize:::

Complete log error:
Copying updated assets files (1)
Application_Start
Device locale: es
Found 161 strings.
*** : B4XPage_Foreground
*** mainpage: B4XPage_Created
Found 161 strings.
Found 161 strings.
Application_Active
*** mainpage: B4XPage_Appear [mainpage]
*** mainpage: B4XPage_Resize [mainpage]
Class (b4i_httpjob) instance released.
Class (b4i_httpjob) instance released.
*** frmxfilter: B4XPage_Created [mainpage]
Error occurred on line: 53 (B4XComboBox)
Target is null. Method called: _initialize:::

Stack Trace: (
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 540460
libobjc.A.dylib objc_exception_throw + 60
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 1582812
PasSportsAr HB +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 160
PasSportsAr HB -[B4ICustomViewWrapper AfterDesignerScript] + 1468
PasSportsAr HB -[B4ILayoutBuilder loadLayout:::] + 1992
PasSportsAr HB -[B4IPanelWrapper LoadLayout::] + 176
PasSportsAr HB -[B4XViewWrapper LoadLayout::] + 80
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 133140
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 129120
PasSportsAr HB +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1296
PasSportsAr HB -[B4IShell runMethod:] + 420
PasSportsAr HB -[B4IShell raiseEventImpl:method:args::] + 1968
PasSportsAr HB -[B4IShellBI raiseEvent:event:params:] + 1360
PasSportsAr HB -[b4i_frmfilterpage _b4xpage_created::] + 360
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 133140
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 129120
PasSportsAr HB +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1296
PasSportsAr HB -[B4ICommon CallSubDebug4::::] + 832
PasSportsAr HB -[B4ICommon CallSubDebug2::::] + 272
PasSportsAr HB -[b4i_b4xpagesmanager _createpageifneeded::] + 888
PasSportsAr HB -[b4i_b4xpagesmanager _showpage::] + 636
PasSportsAr HB -[b4i_b4xpages _showpage:] + 388
PasSportsAr HB -[ResumableSub_b4xmainpage_btnTabMenu_TabClick resume::] + 1672
PasSportsAr HB -[b4i_b4xmainpage _btntabmenu_tabclick::] + 404
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 133140
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 129120
PasSportsAr HB +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1296
PasSportsAr HB -[B4IShell runMethod:] + 420
PasSportsAr HB -[B4IShell raiseEventImpl:method:args::] + 1968
PasSportsAr HB -[B4IShellBI raiseEvent:event:params:] + 1360
PasSportsAr HB -[B4ICommon CallSub4::::] + 240
PasSportsAr HB -[B4ICommon CallSub2::::] + 272
PasSportsAr HB -[b4i_as_tabmenuadvanced _tabclickevent::] + 824
PasSportsAr HB -[b4i_as_tabmenuadvanced _tabclick:::] + 3960
PasSportsAr HB -[b4i_as_tabmenuadvanced _xpnl_tab_click:] + 436
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 133140
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 129120
PasSportsAr HB +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1296
PasSportsAr HB -[B4IShell runMethod:] + 420
PasSportsAr HB -[B4IShell raiseEventImpl:method:args::] + 1968
PasSportsAr HB -[B4IShellBI raiseEvent:event:params:] + 1360
PasSportsAr HB __33-[B4I raiseUIEvent:event:params:]_block_invoke + 52
libdispatch.dylib 81D355DF-266A-3010-BAB8-113B76A206C1 + 8508
libdispatch.dylib 81D355DF-266A-3010-BAB8-113B76A206C1 + 15828
libdispatch.dylib 81D355DF-266A-3010-BAB8-113B76A206C1 + 75172
libdispatch.dylib _dispatch_main_queue_callback_4CF + 44
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 354064
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 342292
CoreFoundation CFRunLoopRunSpecific + 608
GraphicsServices GSEventRunModal + 164
UIKitCore 1741FA37-4E53-371E-8DAE-D611AAB0043D + 4237580
UIKitCore UIApplicationMain + 340
PasSportsAr HB main + 100
dyld 71846EAC-EE65-3697-BF7D-790B6A07DCDB + 249420
)
 
Solution
I finally got it working. This is my analysis, it is speculative and should be corroborated by trying to simulate what I write below in some other project.

If you start your development in B4A and need to make your version in B4I (or B4J), you can copy and paste all the components (text box, panel, image and other compatible elements) of a B4XPage, and thus not perform this design task twice.

You can click in the abstract designer area and press the key combination on the keyboard Control + A to "select all" and Control + C to "copy" to the clipboard.

You must go to the designer in B4I and in its B4XPage version press Control + V to “paste” the contents of the clipboard. As you can see in image 1, it selects all...

Alexander Stolte

Expert
Licensed User
Longtime User
Try to add a sleep(0) between addpage and showpage. In B4A only one panel has to be loaded, everything runs on a single activity. In B4I a new page is created each time, maybe it just takes a little more time which can be fixed with a sleep(0).
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
Try to add a sleep(0) between addpage and showpage. In B4A only one panel has to be loaded, everything runs on a single activity. In B4I a new page is created each time, maybe it just takes a little more time which can be fixed with a sleep(0).
Unfortunately exactly the same thing happens

B4X:
Private Sub btnTabMenu_TabClick (Index As Int)
    Select Case btnTabMenu.GetTab(Index).xTab.Tag
        Case "ChartsDB"
            If Not (frmXCharts.IsInitialized) Then
                frmXCharts.Initialize
                B4XPages.AddPage("frmXCharts", frmXCharts)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXCharts")
        Case "FixtureDB"
            If Not (frmXFixture.IsInitialized) Then
                frmXFixture.Initialize
                B4XPages.AddPage("frmXFixture", frmXFixture)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXFixture")
        Case "LiveResultDB"
            If Not (frmXLiveResults.IsInitialized) Then
                frmXLiveResults.Initialize
                B4XPages.AddPage("frmXLiveResults", frmXLiveResults)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXLiveResults")
        Case "CitationsDB"
            If Not (frmXCitations.IsInitialized) Then
                frmXCitations.Initialize
                B4XPages.AddPage("frmXCitations", frmXCitations)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXCitations")
        Case "SN"
            If Not (frmXSN.IsInitialized) Then
                frmXSN.Initialize
                B4XPages.AddPage("frmXSN", frmXSN)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXSN")
        Case "Filter"
            If Not (frmXFilter.IsInitialized) Then
                frmXFilter.Initialize
                B4XPages.AddPage("frmXFilter", frmXFilter)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXFilter")
        Case "EditUser"
            If Not (frmXEditUser.IsInitialized) Then
                frmXEditUser.Initialize
                B4XPages.AddPage("frmXEditUser", frmXEditUser)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXEditUser")
        Case "UserAttendance"
            If Not (frmXUserAttendance.IsInitialized) Then
                frmXUserAttendance.Initialize
                B4XPages.AddPage("frmXUserAttendance", frmXUserAttendance)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXUserAttendance")
        Case "userDB"
            makeMenu("userDB")
        Case "Options"
            makeMenu("Options")
        Case "Settings"
            If AS_Properties.GetProperty("def_intFed").As (Int) <> -1 Then
                AS_Properties.PutProperty("app_intFed", AS_Properties.GetProperty("def_intFed").As (Int))
            End If
            If AS_Properties.GetProperty("def_intClub").As (Int) <> -1 Then
                AS_Properties.PutProperty("app_intClub", AS_Properties.GetProperty("def_intClub").As (Int))
            End If
            If clvContainer.GetBase.Visible = True Then
                clvContainer.GetBase.Visible = False
            End If
            asdbc_main.Show(True)
            imgBtnSettingsClose.Tag = "close"
        Case "padLockDB"
            Dim sf As Object = xui.Msgbox2Async(mdlFunctions.loc.Localize("started_win_app"), mdlFunctions.loc.Localize("app_name"), mdlFunctions.loc.Localize("yes"), "", mdlFunctions.loc.Localize("cancel"), Null)
            Wait For (sf) Msgbox_Result (Result As Int)
            If Result = xui.DialogResponse_Positive Then
                RunScanQR
            End If
        Case "back"
            makeMenu("main")
        Case "exit"
            Dim sf As Object = xui.Msgbox2Async(mdlFunctions.loc.Localize("exit_app"), mdlFunctions.loc.Localize("app_name"), mdlFunctions.loc.Localize("yes"), "", mdlFunctions.loc.Localize("cancel"), Null)
            Wait For (sf) Msgbox_Result (Result As Int)
            If Result = xui.DialogResponse_Positive Then
                Root.RemoveAllViews
                B4XPages.ClosePage(Me)
                #If B4A
                ExitApplication
                #End If
            End If
    End Select
End Sub

*** : B4XPage_Foreground
*** mainpage: B4XPage_Created
Found 161 strings.
Found 161 strings.
*** mainpage: B4XPage_Appear [mainpage]
*** mainpage: B4XPage_Resize [mainpage]
Application_Active
Class (b4i_httpjob) instance released.
Class (b4i_httpjob) instance released.
*** frmxfilter: B4XPage_Created [mainpage]
Error occurred on line: 53 (B4XComboBox)
Target is null. Method called: _initialize:::
Stack Trace: (
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 540460
libobjc.A.dylib objc_exception_throw + 60
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 1582812
PasSportsAr HB +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 160
PasSportsAr HB -[B4ICustomViewWrapper AfterDesignerScript] + 1468
PasSportsAr HB -[B4ILayoutBuilder loadLayout:::] + 1992
PasSportsAr HB -[B4IPanelWrapper LoadLayout::] + 176
PasSportsAr HB -[B4XViewWrapper LoadLayout::] + 80
PasSportsAr HB -[b4i_frmfilterpage _b4xpage_created::] + 600
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 133140
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 129120
PasSportsAr HB +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1296
PasSportsAr HB -[B4ICommon CallSubDebug4::::] + 832
PasSportsAr HB -[B4ICommon CallSubDebug2::::] + 272
PasSportsAr HB -[b4i_b4xpagesmanager _createpageifneeded::] + 888
PasSportsAr HB -[b4i_b4xpagesmanager _showpage::] + 636
PasSportsAr HB -[b4i_b4xpages _showpage:] + 388
PasSportsAr HB -[ResumableSub_b4xmainpage_btnTabMenu_TabClick resume::] + 5356
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 133140
CoreFoundation 00E76A98-210C-3CB5-930B-F236807FF24C + 129120
PasSportsAr HB +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1296
PasSportsAr HB -[B4IShell runMethod:] + 420
PasSportsAr HB -[B4IShell raiseEventImpl:method:args::] + 1968
PasSportsAr HB -[B4IShellBI raiseEvent:event:params:] + 1360
PasSportsAr HB -[B4IDelegatableResumableSub resume::] + 376
PasSportsAr HB __21-[B4ICommon Sleep:::]_block_invoke + 48
libdispatch.dylib 81D355DF-266A-3010-BAB8-113B76A206C1 + 8508
libdispatch.dylib 81D355DF-266A-3010-BAB8-113B76A206C1 + 15828
libdispatch.dylib 81D355DF-266A-3010-BAB8-113B76A206C1 + 75172
libdispatch.dylib _dispatch_main_queue_callback_4CF + 44
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
Why not write frmXCharts.Initialize and B4XPages.AddPage("frmXCharts", frmXCharts) inside B4XPage_Created?
If you mean doing it within B4XMainPage, it's only to save memory usage resources. If a user, uses 3 out of 10 options, so that they are loaded? I've already tried to change to load all the pages in "created" and the problem is the same
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
If you mean doing it within B4XMainPage, it's only to save memory usage resources. If a user, uses 3 out of 10 options, so that they are loaded? I've already tried to change to load all the pages in "created" and the problem is the same
I don't think doing it in Created will takes up a lot of resources. I think it is the right way to do it. I think you should follow the tutorial on B4XPages.
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
I don't think doing it in Created will takes up a lot of resources. I think it is the right way to do it. I think you should follow the tutorial on B4XPages.



B4X:
Private Sub B4XPage_Created (RootView As B4XView)
    Root = RootView
    Root.LoadLayout("MainPage")


    If Not (frmXCharts.IsInitialized) Then
        frmXCharts.Initialize
        B4XPages.AddPage("frmXCharts", frmXCharts)
    End If
    If Not (frmXFixture.IsInitialized) Then
        frmXFixture.Initialize
        B4XPages.AddPage("frmXFixture", frmXFixture)
    End If
    If Not (frmXLiveResults.IsInitialized) Then
        frmXLiveResults.Initialize
        B4XPages.AddPage("frmXLiveResults", frmXLiveResults)
    End If
    If Not (frmXCitations.IsInitialized) Then
        frmXCitations.Initialize
        B4XPages.AddPage("frmXCitations", frmXCitations)
    End If
    If Not (frmXSN.IsInitialized) Then
        frmXSN.Initialize
        B4XPages.AddPage("frmXSN", frmXSN)
    End If
    If Not (frmXFilter.IsInitialized) Then
        frmXFilter.Initialize
        B4XPages.AddPage("frmXFilter", frmXFilter)
    End If
    If Not (frmXEditUser.IsInitialized) Then
        frmXEditUser.Initialize
        B4XPages.AddPage("frmXEditUser", frmXEditUser)
    End If


    #If B4I
    'AS_TabMenuAdvanced
    xpnl_bottom = xui.CreatePanel("")
    Root.AddView(xpnl_bottom, 0, 0, Root.Width, B4XPages.GetNativeParent(Me).SafeAreaInsets.Bottom)
    xpnl_bottom.Color = 0xFF202125
    'Wait For B4XPage_Resize (Width As Int, Height As Int)
    #End If

    'Localize
    mdlFunctions.loc.LocalizeLayout(Root)
    mdlFunctions.loc.ForceLocale("es")
    'Localize

    toast.Initialize(Root)
    'PUSH
    #if B4A
    CallSubDelayed2(FirebaseMessaging, "SubscribeToTopics", Array("general"))
    'request notification permission
    Wait For (CheckAndRequestNotificationPermission) Complete (HasPermission As Boolean)
    If HasPermission = False Then
        Log("no permission")
        toast.Show(mdlFunctions.loc.Localize("err_no_push_auth"))
    End If
    #End If
    'PUSH

    mdlFunctions.mapApps.Clear
    mdlFunctions.mapApps = clsFunct.GetIMApps
End Sub

B4X:
Private Sub btnTabMenu_TabClick (Index As Int)
    Select Case btnTabMenu.GetTab(Index).xTab.Tag
        Case "ChartsDB"
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXCharts")
        Case "FixtureDB"
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXFixture")
        Case "LiveResultDB"
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXLiveResults")
        Case "CitationsDB"
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXCitations")
        Case "SN"
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXSN")
        Case "Filter"
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXFilter")
        Case "EditUser"
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXEditUser")
        Case "UserAttendance"
            If Not (frmXUserAttendance.IsInitialized) Then
                frmXUserAttendance.Initialize
                B4XPages.AddPage("frmXUserAttendance", frmXUserAttendance)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXUserAttendance")
        Case "userDB"
            makeMenu("userDB")
        Case "Options"
            makeMenu("Options")
        Case "Settings"
            If AS_Properties.GetProperty("def_intFed").As (Int) <> -1 Then
                AS_Properties.PutProperty("app_intFed", AS_Properties.GetProperty("def_intFed").As (Int))
            End If
            If AS_Properties.GetProperty("def_intClub").As (Int) <> -1 Then
                AS_Properties.PutProperty("app_intClub", AS_Properties.GetProperty("def_intClub").As (Int))
            End If
            If clvContainer.GetBase.Visible = True Then
                clvContainer.GetBase.Visible = False
            End If
            asdbc_main.Show(True)
            imgBtnSettingsClose.Tag = "close"
        Case "padLockDB"
            Dim sf As Object = xui.Msgbox2Async(mdlFunctions.loc.Localize("started_win_app"), mdlFunctions.loc.Localize("app_name"), mdlFunctions.loc.Localize("yes"), "", mdlFunctions.loc.Localize("cancel"), Null)
            Wait For (sf) Msgbox_Result (Result As Int)
            If Result = xui.DialogResponse_Positive Then
                RunScanQR
            End If
        Case "back"
            makeMenu("main")
        Case "exit"
            Dim sf As Object = xui.Msgbox2Async(mdlFunctions.loc.Localize("exit_app"), mdlFunctions.loc.Localize("app_name"), mdlFunctions.loc.Localize("yes"), "", mdlFunctions.loc.Localize("cancel"), Null)
            Wait For (sf) Msgbox_Result (Result As Int)
            If Result = xui.DialogResponse_Positive Then
                Root.RemoveAllViews
                B4XPages.ClosePage(Me)
                #If B4A
                ExitApplication
                #End If
            End If
    End Select
End Sub

It doesn't matter which menu icon you select and want to load to the B4XPage, in all cases in some component, it generates an error and the trigger is the "non-initialization" of something internal to iOS, from what I understand what the message says
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
The error seems to point to your frmXFilter - it looks like its trying to initialize a null object.
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
The error seems to point to your frmXFilter - it looks like its trying to initialize a null object.
*** frmxedituser: B4XPage_Created [mainpage]
Error occurred on line: 467 (AS_TextFieldAdvanced)
Target is null. Method called: _initialize:::

No, in any form B4XPage generates the same error and in different components, I don't know if it is the first one that the designer loads
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
maybe as a check
Test if the component is null after the test for IsInitialized
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
Not sure it is related.
Have you checked on B4XPage template that handles iOS safe area ?

I have the same code but it is originally related to the use of AS_TabMenuAdvanced


frmChartsPage:
Private Sub B4XPage_Created (RootView As B4XView)
    Root = RootView
    Root.LoadLayout("frmCharts")

    #If B4I
    'AS_TabMenuAdvanced
    xpnl_bottom = xui.CreatePanel("")
    Root.AddView(xpnl_bottom, 0, 0, Root.Width, B4XPages.GetNativeParent(Me).SafeAreaInsets.Bottom)
    xpnl_bottom.Color = 0xFF202125
    #End If
... continue

B4X:
Private Sub B4XPage_Resize (Width As Int, Height As Int)
#If B4I
    'AS_TabMenuAdvanced
    xpnl_bottom.SetLayoutAnimated(0,0,Height - B4XPages.GetNativeParent(Me).SafeAreaInsets.Bottom,Width,B4XPages.GetNativeParent(Me).SafeAreaInsets.Bottom)
    btnTabMenu.mBase.Top = Height - btnTabMenu.mBase.Height - B4XPages.GetNativeParent(Me).SafeAreaInsets.Bottom
#End If
End Sub
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
I have the same code but it is originally related to the use of AS_TabMenuAdvanced
#If B4I
'AS_TabMenuAdvanced
xpnl_bottom = xui.CreatePanel("")
Root.AddView(xpnl_bottom, 0, 0, Root.Width, B4XPages.GetNativeParent(Me).SafeAreaInsets.Bottom)
xpnl_bottom.Color = 0xFF202125
#End If

Root = RootView
Root.LoadLayout("frmCharts")

In the example, the code for B4I is prior to loading the Layout, I am going to try inverting that segment of the code
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
The same problem. There I reverted all the changes and verified the normal operation of B4A. Anyone with the B4I license and knowledge can privately share the original project with them without any problem.
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
Hello everyone, I made this modification (AddPageAndCreate)

B4X:
Case "Filter"
    If Not (frmXFilter.IsInitialized) Then
        frmXFilter.Initialize
        B4XPages.AddPageAndCreate("frmXFilter", frmXFilter)
    End If
    B4XPages.ShowPage("frmXFilter")

1720454297013.png


I made a step in (F8) and it breaks on line 105. I don't know what to do @Erel. Do you think that by copying and pasting from one platform to another I made a mistake?
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
You can easily check this by clicking on a custom view and if the type does not contain the name of the view, but "Panel", then you know that something was wrong when you inserted it.
 
Upvote 0
Top