B4J Question I have a problem: I compiled a program using B4J

Cesar_Morisco

Active Member
Licensed User
Longtime User
Hello everyone, hope you are doing well!

I have a problem: I compiled a program using B4J, but when I try to run it on Windows 10, it seems like it starts but nothing happens. The executable file is generated correctly, but it doesn’t launch.

Some important details:

System: Windows 10 64-bit

Java installed: java version "1.8.0_461" (64-bit)

[CODE lang="b4x" title="b4j"]#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region

#Region Form Preperation
'Template version 1.00
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private MenuBar1 As MenuBar
Private astream As AsyncStreams
Private serial As Serial
Private DataFolder As String
Private FRE As Button
Private TRA As Button
Private ESQ As Button
Private DIR As Button
Private FAR As Button
Private cmbPort As ComboBox
Private PortsNames As B4XOrderedMap
Private udpListener As UDPSocket
Private const BAUDRATE As Int = 9600
Private const settingsFile As String = "Settings.txt"
Private connected As Boolean
Private Conectar As Button
Private TextArea1 As TextArea
Private chkReset As CheckBox
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Main")
MainForm.Show

DataFolder = File.DirData("SerialConnector")
serial.Initialize("")
Wait For (GetPortsNames) Complete (unused As Boolean)
cmbPort.Items.AddAll(PortsNames.Values)
If File.Exists(File.DirApp, settingsFile) Then
Dim m As Map = File.ReadMap(File.DirApp, settingsFile)
If m.ContainsKey("port") Then
Dim SavedPort As String = m.Get("port")
If PortsNames.ContainsKey(SavedPort) Then
cmbPort.SelectedIndex = cmbPort.Items.IndexOf(PortsNames.Get(SavedPort))
End If
End If
chkReset.Checked = m.Get("reset")
End If
If cmbPort.SelectedIndex = -1 Then cmbPort.SelectedIndex = cmbPort.Items.Size - 1
udpListener.Initialize2("udp", 51042, 8192, True, True)

End Sub
Sub GetPortsNames As ResumableSub
PortsNames.Initialize
For Each port As String In serial.ListPorts
PortsNames.Put(port, port) 'default names
Next
File.Copy(File.DirAssets, "ListPorts.exe", DataFolder, "ListPorts.exe")
Dim shl As Shell
shl.Initialize("shl", File.Combine(DataFolder, "ListPorts.exe"), Null)
shl.Run(5000)
Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
If Success And ExitCode = 0 Then
For Each line As String In Regex.Split(CRLF, StdOut)
Log(line)
Dim i As Int = line.IndexOf(" ")
If i = -1 Then Continue
Dim port As String = line.SubString2(0, i)
Dim Description As String = line.Trim
If PortsNames.ContainsKey(port) Then PortsNames.Put(port, Description)
Next
End If
Return True
End Sub
Sub btnOpen_Action
OpenAction(True)
End Sub
Sub OpenAction(User As Boolean)
If connected Then
connected = False
astream.Close
serial.Close
Conectar.Text = "Open"
Return
End If
If User Then
OpenAfterDelay
Else
Sleep(8000)
OpenAfterDelay
End If

End Sub

Private Sub OpenAfterDelay
If cmbPort.SelectedIndex = -1 Then Return
Try
serial.Open(PortsNames.Keys.Get(cmbPort.SelectedIndex))
If chkReset.Checked Then
serial.SetParams(BAUDRATE, 8, 1, 0)
Else
Dim jo As JavaObject = serial
jo = jo.GetField("sp")
jo.RunMethod("setParams", Array(BAUDRATE, serial.DATABITS_8, serial.STOPBITS_1, serial.PARITY_ODD, False, False))
End If
astream.Initialize(serial.GetInputStream, serial.GetOutputStream, "astream")
FRE.Enabled = True
Conectar.Text = "Close"
Catch
Log(LastException)
fx.Msgbox(MainForm, "Failed to open port", "")
End Try
connected = True
Conectar.Enabled = connected
btnClear_Action
End Sub
Sub btnClear_Action
TextArea1.Text = ""
End Sub

Sub MainForm_Closed
Dim m As Map = CreateMap("reset": chkReset.Checked)
If cmbPort.SelectedIndex > -1 Then m.Put("port", PortsNames.Keys.Get(cmbPort.SelectedIndex))
File.WriteMap(File.DirApp, settingsFile, m)
End Sub

Private Sub UDP_PacketArrived (Packet As UDPPacket)
Try
Dim s As String = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "utf8")
If s.StartsWith("B4R") = False Then Return
Dim msg() As String = Regex.Split(",", s)
If msg.Length < 3 Or cmbPort.SelectedIndex = -1 Then Return
If msg(1) = PortsNames.Keys.Get(cmbPort.SelectedIndex) Then
If connected <> msg(2) Then
OpenAction(False)

End If
End If
Catch
Log(LastException)
End Try
End Sub[/CODE]
 
In B4J paths is it set to that Java Version?
 
Upvote 0
In B4J paths is it set to that Java Version?
B4J Versão: 10.30
Analisando o código. (0.02s)
Java Versão: 19
Building folders structure. (0.01s)
Compilando o código (0.02s)
Compilando código dos layouts. (0.00s)
Organizando bibliotecas (0.00s)
Compilando o código Java. (1.99s)
Construindo arrquivo jar. (0.45s)
Arquivo Jar criado: C:\Users\centr\Desktop\Robo_Controle\Robo_Controle\Objects\Robo_Controle.jar
Executando aplicação. (0.00s)
Concluído com sucesso
 
Upvote 0
After Java 8 the jars are no more self executable.
 
Upvote 0
After Java 8 the jars are no more self executable.
Even compiling the way you told me, this file doesn’t open on my computer. I’ve tried everything, I don’t know why it won’t open. It looks like it’s going to open, but it can’t.



InputJar: C:\Users\centr\Desktop\Robo_Controle\Robo_Controle\Objects\Robo_Controle.jar
Running: C:\Users\centr\Desktop\ROBO_C~1\ROBO_C~1\Objects\temp\FindDosPath.exe
Running: C:\java\jdk-19.0.2\bin\jar
Package name: b4j.example
Running: C:\java\jdk-19.0.2\bin\jdeps
.
Explicitly excluded modules: [javafx.web]
Included modules: [java.base, java.desktop, java.logging, javafx.base, javafx.controls, javafx.fxml, javafx.graphics, javafx.media, javafx.swing]
Running: C:\java\jdk-19.0.2\bin\javac
.
Running: C:\java\jdk-19.0.2\bin\jar
Running: C:\java\jdk-19.0.2\bin\jlink
.
.
.
.
.
.
.
.
Running: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe
Running: explorer.exe
Done!
 
Upvote 0
Are you launching the EXE from inside its folder?
You cannot take it out.
It must be executed inside the Build folder (of course you can rename it).
 
Upvote 0
Are you launching the EXE from inside its folder?
You cannot take it out.
It must be executed inside the Build folder (of course you can rename it).
Yes, even running it inside the folder you mentioned, it still doesn’t open. I don’t understand
 
Upvote 0
So I think that it's needed some more information about the project.
Which libraries you are using and so on.
It could be needed to add some lines to add components with
#PackagerProperty
But here it's needed some more experienced user in the case.
 
Upvote 0
So I think that it's needed some more information about the project.
Which libraries you are using and so on.
It could be needed to add some lines to add components with
#PackagerProperty
But here it's needed some more experienced user in the case.
 
Upvote 0
Have you tried if with a simple Hello World project it works?
 
Upvote 0
Last edited:
Upvote 0
Even compiling the way you told me, this file doesn’t open on my computer. I’ve tried everything, I don’t know why it won’t open. It looks like it’s going to open, but it can’t.



InputJar: C:\Users\centr\Desktop\Robo_Controle\Robo_Controle\Objects\Robo_Controle.jar
Running: C:\Users\centr\Desktop\ROBO_C~1\ROBO_C~1\Objects\temp\FindDosPath.exe
Running: C:\java\jdk-19.0.2\bin\jar
Package name: b4j.example
Running: C:\java\jdk-19.0.2\bin\jdeps
.
Explicitly excluded modules: [javafx.web]
Included modules: [java.base, java.desktop, java.logging, javafx.base, javafx.controls, javafx.fxml, javafx.graphics, javafx.media, javafx.swing]
Running: C:\java\jdk-19.0.2\bin\javac
.
Running: C:\java\jdk-19.0.2\bin\jar
Running: C:\java\jdk-19.0.2\bin\jlink
.
.
.
.
.
.
.
.
Running: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe
Running: explorer.exe
Done!
Running run_debug.bat, you will see an error message, which may be caused by the lack of jssc.dll, the solution is at #post12
 
Upvote 0
I suggest you take a look at https://www.b4x.com/android/forum/t...-way-to-distribute-standalone-ui-apps.117880/, specifically Tips and special cases 5. which says:

If using jSerial put the attached jssc.dll file in the project folder and add:
B4X:
#CustomBuildAction: After Packager, %WINDIR%\System32\robocopy.exe, ..\ temp\build\bin\ jssc.dll
Note that it is a Windows 64 bit dll.
Bingo, thanks to all of you!
And my first B4J project using this Ariel example!
Thank you so much! I love you all!
 
Upvote 0
Back
Top