Android Question Show Page Code Closes App?

Status
Not open for further replies.
First Project and having issues with showing a 2nd page.

Iam thinking its because the page is not being added to the Files manager?

B4X:
Private Sub Button1_Click
    B4XPages.ShowPage("NumberPage")
End Sub
 

Attachments

  • Screenshot 2025-01-06 100746.png
    52.7 KB · Views: 30
Solution
This thread is a good example of how not to ask a question.

The correct way is:

1. This is my code:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click
'    xui.MsgboxAsync("Hello world!", "B4X")
'    StartActivity.LoadLayout("LeftSide")
'    Activity.LoadLayout("LeftSide")
'    B4XPages.ShowPage("LeftSide")...
ok, i done that, did you get it as i don't get any confirmation its been sent

B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This thread is a good example of how not to ask a question.

The correct way is:

1. This is my code:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click
'    xui.MsgboxAsync("Hello world!", "B4X")
'    StartActivity.LoadLayout("LeftSide")
'    Activity.LoadLayout("LeftSide")
'    B4XPages.ShowPage("LeftSide")
    B4XPages.ShowPage("LeftSide")
End Sub

When the button is clicked the app crashes with these logs:

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
Error: page id not found: LeftSide
Ids: (ArrayList) [mainpage]
Error occurred on line: 38 (B4XOrderedMap)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
at b4a.example.b4xpagesmanager._showpage(b4xpagesmanager.java:421)
at b4a.example.b4xpages._showpage(b4xpages.java:29)
at b4a.example.b4xmainpage._button1_click(b4xmainpage.java:66)
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:157)
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:8033)
at android.view.View.performClickInternal(View.java:8010)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:31336)
at android.os.Handler.handleCallback(Handler.java:991)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8787)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:871)

Answer: don't miss this line: Error: page id not found: LeftSide
You forgot to add the page with B4XPages.AddPage. See the example: https://www.b4x.com/android/forum/t...k-for-managing-multiple-pages.118901/#content
 
Upvote 0
Solution
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…