B4J Question packaged java program closes on Serial port Open

Discussion in 'B4J Questions' started by nibelugen, Sep 2, 2017.

  1. nibelugen

    nibelugen Member Licensed User

    I authored a B4J program, that compiles and runs fine as a jar file. I tried packaging it using the self contained installer as detailed here,
    https://www.b4x.com/android/forum/threads/ui-apps-packaging-self-contained-installers.56854/

    The packager executes fine, and I end up with an installable program. I installed the packaged program on three different computers, two Windows 10, and 1 Windows 7. When running the program the first thing the end user must do is select a COM serial port. On the Windows 10 systems, immediately when the port is selected, and the program line
    Serial1.Open(cmbPort.Value) is encountered, the program closes. If I run the compiled jar program in the same installed program app subdirectory, it runs fine. In the log file, it shows that COM1 is selected as the value - and I even tried to manually select it in the program with Serial1.Open("COM1"), but it immediately closes with the packaged and installed executable, but works fine as the jar file. I am out of ideas. Here are the lines of code that are terminating the installed program,

    astream.Close
    Serial1.Close
    Serial1.Initialize("")
    Log("<" & cmbPort.Value & ">")
    Serial1.Open(cmbPort.Value)

    Please help, as I can't distribute the program. Thanks.
     
    micro likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    Have you ran the jar file that is in the app folder? You should run it from the command line and see the error message.
     
  3. nibelugen

    nibelugen Member Licensed User

    Yes, I tried running the .jar program from the app folder of the installed program, and it works fine. I tried using the command line as well to run this same .jar app. Doing it this way I can see echoed in the command line window the com port I selected, usually COM1, but there is no error when it runs as the .jar app, there's nothing to log with catch. I tried running the installation file as windows 7 compatible; tried running the program as windows 7 compatible, and I get the same failure. It's baffling. I just tried it on a third windows 10 computer, and it fails the same way.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Things to try:

    1. Show a msgbox with the error and return false from Application_Error.
    2. Run it as an administrator.
     
  5. nibelugen

    nibelugen Member Licensed User

    I added the msgbox, return false, run as administrator, and still cannot discover the problem. So, I tried using existing program, B4J_Chat, found at,
    https://www.b4x.com/android/forum/threads/jserial-library.34762/#content

    To this program, at the very end of it I added msgbox,

    Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Dim Msgbox As Msgboxes
    LogError("App Error log = <" & Error & "> " & "<" & StackTrace & ">")
    Msgbox.Show("App Error log = <" & Error & ">" & " " & "<" & StackTrace & ">", "App Error log")
    Return False
    ' Return True
    End Sub

    I packaged it using B4J Packager, found at
    https://www.b4x.com/android/forum/threads/ui-apps-packaging-self-contained-installers.56854/

    Ultimately, it generated the installation file, ChatTest-1.0.exe (compressed .zip attached).

    I install and run it, and as soon as I try to open any serial COM port, by clicking on the OPEN button, it closes. There are no messages, error or otherwise.

    If I try to run the original java file from the installed app directory in a command prompt, using java -jar <java_program>, it does not close and appears to run fine, and I can send text to the selected port. When I close the program though, I do get an error message,

    upload_2017-9-3_11-48-37.png
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    It probably fails to copy the native so library.

    Please add this code:
    Code:
    Dim s As String = $"
    osName = ${
    GetSystemProperty("os.name""NA")}
    architecture = ${
    GetSystemProperty("os.arch""NA")}
    userHome = ${
    GetSystemProperty("user.home""NA")}
    fileSeparator = ${
    GetSystemProperty("file.separator""NA")}
    tmpFolder = ${
    GetSystemProperty("java.io.tmpdir""NA")}
    "$

    fx.Msgbox(MainForm, s, 
    "")
    Is there any difference in the result when you run it with java -jar compared to running the executable?
     
  7. nibelugen

    nibelugen Member Licensed User

    The java -jar runs fine; the java program is fine. The executable does not run, closing immediately on selecting any serial port. I also tried using the chat program, B4J_Chat, that is available on this site and found at,
    https://www.b4x.com/android/forum/threads/jserial-library.34762/#content

    After packaging and then installing and running it, it exhibits the same problem; after selecting any serial port, immediately on clicking the open button it closes - there are no error messages, it just instantly closes. Using and running the program from command line with java -jar, and it works fine. After packaging, I tried installing the program on 4 different computers - 3 Windows 10, and 1 Windows 7. The Windows 7 program installs and works correctly. The Windows 10 program installs correctly but on opening the serial port, it instantly closes - on all 3 Windows 10 computers. I tried many different ways to circumvent and understand the problem, including running as administrator, and running in Windows 7 compatible, and it just doesn't work.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Have you seen my previous post?
     
  9. nibelugen

    nibelugen Member Licensed User

    I have seen all of the replies on this thread, and have implemented and tested these, as well as my own attempted solutions, and cannot resolve the problem.

    Also and factually, this website's own chat program doesn't work when packaged either. Here is a link to this website chat program,
    https://www.b4x.com/android/forum/threads/jserial-library.34762/#content

    When packaged and run on Windows 10 - three different computers, it closes immediately on OPEN port button. It works fine packaged on Windows 7 computer, but not Windows 10.

    Perhaps if the Chat program can be made to work, I could then implement that solution for my own purpose. Thanks.
     
    Last edited: Sep 30, 2017
  10. Erel

    Erel Administrator Staff Member Licensed User

    I've asked you to provide information about several paths.
     
  11. nibelugen

    nibelugen Member Licensed User

    You did inquire about several paths, and I've tried them all. Here they are summarized:

    'Begin Summary
    Erel: Have you ran the jar file that is in the app folder? You should run it from the command line and see the error message.
    nib: Yes, it runs fine - there is no error message

    Erel:
    1. Show a msgbox with the error and return false from Application_Error.
    2. Run it as an administrator.
    nib:
    1) no Application Error appears and the packaged program crashes on Serial port open
    2) Ran as administrator and the packaged program crashes on Serial port open

    Erel:
    Please add this code:
    osName = ${GetSystemProperty.....
    .... "$
    fx.Msgbox(MainForm, s, "")
    nib:
    Added the code, and it gives predictable information,
    osName = Windows 10
    architecture = amd64
    userHome = C:\Users\Michael
    fileSeperator = \
    tmpFolder = C:Users\Michael\AppData\Local\Temp\

    Erel: Is there any difference in the result when you run it with java -jar compared to running the executable?
    nib: it runs fine with java -jar - no error messages

    'End Summary

    I found that the problem appears even when using this websites own Chat program, which can be found here
    https://www.b4x.com/android/forum/threads/jserial-library.34762/#content

    when packaged using this website's self contained installer which can be found here
    https://www.b4x.com/android/forum/threads/ui-apps-packaging-self-contained-installers.56854/#content

    it crashes on Serial port open

    To capture the error, I added logError and LastException in the existing program subroutine, btnOpen_Action,
    Try
    sp.Open(cmbPort.Value)
    Catch
    LogError(LastException.Message)
    End Try

    It crashed on Serial port open, reporting excerpt:

    #
    # A fatal error has been detected by the Java Runtime Environment:
    #
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007110b5db, pid=12512, tid=0x0000000000003244
    #
    # JRE version: Java(TM) SE Runtime Environment (8.0_121-b13) (build 1.8.0_121-b13)
    # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.121-b13 mixed mode windows-amd64 compressed oops)
    # Problematic frame:
    # C [jSSC-2.8_x86_64.dll+0xb5db]
    #
    ........
    ........
    Stack: [0x0000000b86800000,0x0000000b86900000], sp=0x0000000b868fd3c0, free space=1012k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    C [jSSC-2.8_x86_64.dll+0xb5db]
    C [jSSC-2.8_x86_64.dll+0x12590]
    C [jSSC-2.8_x86_64.dll+0x1595]
    C 0x000001f6318e925b
    Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
    j jssc.SerialNativeInterface.openPort(Ljava/lang/String;Z)J+0
    j jssc.SerialPort.openPort()Z+65
    j anywheresoftware.b4j.serial.Serial.Open(Ljava/lang/String;)V+16
    j b4j.example.main._btnopen_action()Ljava/lang/String;+201
    v ~StubRoutines::call_stub
    j sun.reflect.NativeMethodAccessorImpl.invoke0(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+0
    j sun.reflect.NativeMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+100
    J 1189 C1 sun.reflect.DelegatingMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (10 bytes) @ 0x000001f631ceac44 [0x000001f631ceab40+0x104]
    J 1188 C1 java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (62 bytes) @ 0x000001f631ce98ac [0x000001f631ce94c0+0x3ec]
    j anywheresoftware.b4a.BA.raiseEvent2(Ljava/lang/Object;ZLjava/lang/String;Z[Ljava/lang/Object;)Ljava/lang/Object;+76
    j anywheresoftware.b4a.BA$1.run()V+18
    j com.sun.javafx.application.PlatformImpl.lambda$null$173(Ljava/lang/Runnable;)Ljava/lang/Void;+1
    j com.sun.javafx.application.PlatformImpl$$Lambda$52.run()Ljava/lang/Object;+4
    v ~StubRoutines::call_stub
    J 1550 java.security.AccessController.doPrivileged(Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;)Ljava/lang/Object; (0 bytes) @ 0x000001f631dac4a6 [0x000001f631dac440+0x66]
    j com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Ljava/lang/Runnable;Ljava/security/AccessControlContext;)V+7
    j com.sun.javafx.application.PlatformImpl$$Lambda$50.run()V+8
    j com.sun.glass.ui.InvokeLaterDispatcher$Future.run()V+4
    v ~StubRoutines::call_stub
    j com.sun.glass.ui.win.WinApplication._runLoop(Ljava/lang/Runnable;)V+0
    j com.sun.glass.ui.win.WinApplication.lambda$null$148(ILjava/lang/Runnable;)V+8
    j com.sun.glass.ui.win.WinApplication$$Lambda$40.run()V+12
    j java.lang.Thread.run()V+11
    v ~StubRoutines::call_stub
     
  12. OliverA

    OliverA Expert Licensed User

    It looks like it's a combo of using an EXE to launch a jar file and Windows 10 (see this stackoverflow post) and not related to B4J itself (nor the wrap of JSSC).

    Edit: This post (here) may contain the answer: use 32 bit Java.
     
    Erel likes this.
  13. Erel

    Erel Administrator Staff Member Licensed User

    This is indeed the exact same error report: https://github.com/scream3r/java-simple-serial-connector/issues/112

    What I meant to ask is, does the msgbox show the exact same information in both cases?
     
  14. nibelugen

    nibelugen Member Licensed User

    Both references and examples provided by OliverA and Erel are exactly what I am experiencing; the native launcher .exe crashes on serial port open, while the .jar works fine. The captured exception error I get is identical to that reported in the other references. Then too, on the stackoverflow link, it is stated that the .exe works on Windows 7 and not Windows 10, and that is my experience too.

    One more detail in reply to Erel; the msgbox shows the exact same information in both cases .exe and .jar.

    As hinted at, I tried compiling the Chat program 32 bit. As before, after installation the .exe crashes on Serial port open, while the .jar works.
     
    Erel likes this.
  15. OliverA

    OliverA Expert Licensed User

    When you compiled for 32 bit, what is the LastException.Message? (Please post)
     
  16. nibelugen

    nibelugen Member Licensed User

    So I tested this Chat program now a zillion different ways, using jdk 9, 1.8.0_121, 1.8.0_65, 1.7.0_55 (x86). The results are indicated in the informal results table below. (key: SO = Serial Port Open)

    What is especially interesting, is that when using the latest java jdk-9 (released just days ago), the Chat program crashes on SO in the B4J IDE, crashes on SO as compiled jar, and cannot be compiled as a .exe. When it crashes, the logged error message is the same,

    # A fatal error has been detected by the Java Runtime Environment:
    #
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007110b5db, pid=12496, tid=11440
    #
    # JRE version: Java(TM) SE Runtime Environment (9.0+181) (build 9+181)
    # Java VM: Java HotSpot(TM) 64-Bit Server VM (9+181, mixed mode, tiered, compressed oops, g1 gc, windows-amd64)
    # Problematic frame:
    # C [jSSC-2.8_x86_64.dll+0xb5db]
    #
    ... which traces back to jssc serial port open as above.

    When compiled as 32 bit using 7.0_55, I get the same error message, EXCEPTION_ACCESS_VIOLATION (0xc0000005), which traces back to serial port open as above.

    Informal Results Table
    B4J IDE Tools, Configure Paths = C:\Program Files\Java\jdk-9\bin\javac.exe
    Crashes on SO in B4J IDE, crashes on SO as compiled jar, cannot compile native .exe - error: no application jars found (even though it really does exist)

    B4J IDE Tools, Configure Paths = C:\Program Files\Java\jdk1.8.0_121\bin\javac.exe
    Runs in B4J IDE, runs as compiled jar, crashes on SO as native .exe

    B4J IDE Tools, Configure Paths = C:\Program Files\Java\jdk1.8.0_65\bin\javac.exe
    Runs in B4J IDE, runs as compiled jar, crashes on SO as native .exe

    B4J IDE Tools, Configure Paths = C:\Program Files (x86)\Java\jdk1.7.0_55\bin\javac.exe (program) and C:\Program Files\Java\jdk1.8.0_65\bin\javac.exe (packager)
    Does not run in B4J IDE, crashes on SO as compiled jar, crashes on SO as native .exe
     
  17. OliverA

    OliverA Expert Licensed User

    The two posts of the "#A fatal error has been detected" messages show that you are using 64 bit java with the 64 bit jSSC dll. In the "Informal Results Table", the only time I see a 32 bit Java is the in fourth entry, but even then, you use the 64 bit java for the packager. Even stranger, that entry shows that you are not only using different "bitness" of Java, but you are using different Java versions. Have you tried 32 bit java for both the B4J IDE and the packager (with both Java version being the same)? If so, what error message are you getting (still a "#A fatal error has ben detected")?
     
  18. nibelugen

    nibelugen Member Licensed User

    I am using the java packager program which can be found on this website here,
    https://www.b4x.com/android/forum/threads/ui-apps-packaging-self-contained-installers.56854/
    This program uses javapackager which is only available in the 64 bit Program Files directory. When packaging the jar, B4JPackager defaults to using the javapackager jre. For the Chat program 32bit test, I chose for the javapackager jdk \Program Files\Java\jdk1.8.0_65 - there is no 32bit choice for javapackager. That's why I've indicated in my Informal Results Table the Chat program compiled 32 bit (\Program Files (x86)\Java\jdk1.7.0_55\), and the packager 64 bit (\Program Files\Java\jdk1.8.0_65\)- there are no other choices.

    However, when packaging, I can redirect the jre to be used by the target program "Chat" by changing a line in the B4JPackager program, from
    ' args.Add("-Bruntime=" & GetSystemProperty("java.home", ""))
    ... which sets the default Chat jre to the same as javapackager (which can only be 64 bit)
    to
    ' args.Add("-Bruntime=C:\Program Files (x86)\Java\jdk1.7.0_55\jre")
    ... which sets the default Chat jre to 32 bit.

    When I do this though, it fails to compile an installable packaged program. The best I could do then is compile the Chat program 32 bit, using the javapackager 64bit, with a Chat program 64 bit jre the same as the javapackager.

    To me what's really suspicious is that when using the latest JDK-9 for everything - compile Chat, javapackager, Chat using jre9, the Chat program crashes on SO when executing in Release or Debug within B4J IDE, and when running the compiled Chat.jar program, and a fatal error trying to run the javapackager. These first two suggest a B4J jSerial Library problem (I'm using jSerial 1.20)

    In fact, right in the log window now of the B4J IDE I get the familiar error message,
    #
    # A fatal error has been detected by the Java Runtime Environment:
    #
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007110b5db, pid=5040, tid=14604
    #
    # JRE version: Java(TM) SE Runtime Environment (9.0+181) (build 9+181)
    # Java VM: Java HotSpot(TM) 64-Bit Server VM (9+181, mixed mode, tiered, compressed oops, g1 gc, windows-amd64)
    # Problematic frame:
    # C [jSSC-2.8_x86_64.dll+0xb5db]
    #

    And not surprisingly, I also now get this same error message when using java -jar Chat.jar - all when using JDK-9.
     
  19. OliverA

    OliverA Expert Licensed User

    Huh? I have (just for kicks) installed the 32 bit version of the JDK (Java SE Development Kit 8u144), and the javapacker.exe is where it is supposed to be. Please see attached picture for configuration of B4J, the Packager application and a running of the final result. Please note since I have no serial ports (nor anything Bluetooth related to test with), I can't try to open a port and see what happens. I have shown though that a 32bit program, using the 32bit JDK, can be created. My host operating system is Windows 10 Pro (version 1703, OS Build 15063.608).
     

    Attached Files:

    Last edited: Oct 6, 2017
  20. OliverA

    OliverA Expert Licensed User

    Since there does not seem to exist a 32bit version of the JDK 9 and the issue may be related to 64 vs 32 bittines, this is a moot point for now.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice