Android Question Convert app from B4A to B4J

racleta31

Member
Hello. I have developed an app using B4A and i need it to be usable on Windows. I would need some advice on how to translate it to B4J and if there are any useful apps that might do this work for me.

Thank you!
 

racleta31

Member
Thank you for the answer.

Now I have another problem: I copied the code from the booklet and i run into this error:

B4X:
b4xpagesmanager._createpageifneeded (java line: 304)
java.lang.RuntimeException: java.lang.NullPointerException
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:513)
    at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:459)
    at b4j.L2P.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:304)
    at b4j.L2P.b4xpagesmanager._showpage(b4xpagesmanager.java:719)
    at b4j.L2P.b4xpagesmanager._addpage(b4xpagesmanager.java:116)
    at b4j.L2P.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:123)
    at b4j.L2P.b4xpagesmanager._initialize(b4xpagesmanager.java:488)
    at b4j.L2P.main._appstart(main.java:61)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
    at b4j.L2P.main.start(main.java:37)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException
    at b4j.L2P.b4xcombobox._setitems(b4xcombobox.java:291)
    at b4j.L2P.b4xmainpage._fillcombobox(b4xmainpage.java:108)
    at b4j.L2P.b4xmainpage._b4xpage_created(b4xmainpage.java:50)
    at b4j.L2P.b4xmainpage.callSub(b4xmainpage.java:141)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:488)
    ... 23 more

Any reason for this to happen? I read on another article that it might be caused by the antivirus, so i set the folder with the app and the build as exceptions for my Kaspersky antivirus. Yet nothing happened. It starts the app and it gets closed immediately.
 
Upvote 0

racleta31

Member
This is what I get when compiling with Debug (the other post was when compiling with Release).

Waiting for debugger to connect...
Program started.
Error occurred on line: 51 (B4XMainPage)
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:477)
at b4j.L2P.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:867)
at b4j.L2P.b4xpagesmanager._showpage(b4xpagesmanager.java:346)
at b4j.L2P.b4xpagesmanager._addpage(b4xpagesmanager.java:175)
at b4j.L2P.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:189)
at b4j.L2P.b4xpagesmanager._initialize(b4xpagesmanager.java:125)
at b4j.L2P.main._appstart(main.java:85)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at b4j.L2P.main.start(main.java:38)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:134)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:81)
... 35 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:115)
... 36 more
Caused by: java.lang.RuntimeException: Class instance was not initialized (b4xcombobox)
at anywheresoftware.b4a.debug.Debug.shouldDelegate(Debug.java:45)
at b4j.L2P.b4xcombobox._setitems(b4xcombobox.java:53)
at b4j.L2P.b4xmainpage._fillcombobox(b4xmainpage.java:105)
at b4j.L2P.b4xmainpage._b4xpage_created(b4xmainpage.java:68)
... 41 more
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Any reason for this to happen?
Any reason for not uploading a small project showing the problem?
How could we help with this - zero - Information?
 
Upvote 0

racleta31

Member
Sorry, as I said i copied word to word what was there in the booklet.
B4XMainPage:
#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

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
   
   
    Private Page1 As B4XPage1
    Private lblPage1 As B4XView
    Private xcbxMainPage As  B4XComboBox
   
    Public SelectedIndex As Int 'Selected index'
    Public SelectedItem As String 'Selected item'
   
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")
   
    Page1.Initialize
    B4XPages.AddPage("Page 1", Page1)

    FillComboBox
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")
End Sub

Private Sub FillComboBox
    Private i As Int
    Private lst As List
   
    lst.Initialize
    For i=0 To 10
        lst.Add("Main" & i)
    Next
    xcbxMainPage.SetItems(lst)
   
    xcbxMainPage.SelectedIndex = SelectedIndex
    SelectedItem = xcbxMainPage.SelectedItem ' memorise  the index'
   
End Sub

Private Sub btnPage1_Click
    B4XPages.ShowPage("Page 1")
   
End Sub

Private Sub xcbxMainPage_SelectedIndexChanged (Index As Int)
    SelectedIndex = Index 'memorise the index
    SelectedItem = xcbxMainPage.SelectedItem ' memorise the index
End Sub
Public Sub Update
    lblPage1.Text = Page1.SelectedItem
End Sub

EDIT : Because my answers have to be approved by a moderator, I can't reply in time to your answers. Maybe now you can help me, with the code
 
Last edited:
Upvote 0

josejad

Expert
Licensed User
Longtime User
What version of B4A are you using?
Make sure you're using the last version
 
Upvote 0

racleta31

Member
I have installed B4J yesterday.
I got home from work and tried to rewrite everything on another laptop, still the same issue. This is the project, in B4XPages.
Thank you for the answers so far.
 

Attachments

  • Crossplatform.zip
    3.7 KB · Views: 110
Upvote 0

racleta31

Member
I have managed to solve this problem. Thank you for all the help!

I have got one more question

In my B4A app I am using a lot of specific B4A libraries, is there anything else to do rather than looking for the corresponding B4J libraries or changing the code in a way the app depends less on those libraries in the first place(therefore changing it in B4A aswell)?
 
Upvote 0
Top