B4J Question Java locale language in the IDE logs

peacemaker

Expert
Licensed User
Longtime User
Hi, All

1693142592238.png


Tried
Dim jo As JavaObject
jo.InitializeStatic("java.util.Locale").RunMethod("setDefault", Array(jo.GetField("US")))

and
B4X:
#VirtualMachineArgs: -Duser.language=en -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8

But currently the output of "java -XshowSettings -version" is:
java.vm.specification.name = Java Virtual Machine Specification
java.vm.specification.vendor = Oracle Corporation
java.vm.specification.version = 14
java.vm.vendor = Oracle Corporation
java.vm.version = 14.0.1+7
jdk.debug = release
line.separator = \r \n
os.arch = amd64
os.name = Windows 10
os.version = 10.0
path.separator = ;
sun.arch.data.model = 64
sun.boot.library.path = d:\Programs\Java\jdk-14.0.1\bin
sun.cpu.endian = little
sun.cpu.isalist = amd64
sun.io.unicode.encoding = UnicodeLittle
sun.java.launcher = SUN_STANDARD
sun.jnu.encoding = Cp1251
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
sun.os.patch.level =
sun.stderr.encoding = cp866
sun.stdout.encoding = cp866
user.dir = d:\Programs\Java\jdk-14.0.1\bin

did not help... How to fix ?
 
Last edited:

teddybear

Well-Known Member
Licensed User
I don't think the error is related to locale language or encoding, it may be an encoding issue with the file name or directory under ..\orion_fw_updater\...
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
It's just trying to download file:
B4X:
Sub DownloadAndSave (Url As String, dir1 As String, FileName As String) As ResumableSub
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(Url)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim out As OutputStream = File.OpenOutput(dir1, FileName, False) 'ERROR IS HERE
        File.Copy2(j.GetInputStream, out)
        out.Close
    End If
    j.Release
    Return j.Success
End Sub


WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
esptool.exe --port COM13 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0x10000 src.ino.bin
value = COM13
Error occurred on line: 685 (B4XMainPage)
java.io.FileNotFoundException: C:\Users\VLAD-HP\AppData\Roaming\orion_fw_updater\s01_00500_v0.843.bin
(Синтаксическая ошибка в имени файла, имени папки или метке тома)
at java.base/java.io.FileOutputStream.open0(Native Method)
at java.base/java.io.FileOutputStream.open(FileOutputStream.java:291)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:234)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:465)
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:564)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:21)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:156)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:514)
at anywheresoftware.b4a.keywords.Common.access$0(Common.java:494)
at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:568)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
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:832)

I have decoded this error, but question is to make EN output.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
But currently the output of "java -XshowSettings -version" is:
It has nothing to do with your app process.

Unless you are using Java 16+ you don't need to do anything for the logs to be encoded with UTF8. With Java 16+ there is indeed a new flag that needs to be set.
If you see garbled characters then the problem is somewhere else (but first delete the VM args you set).
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
My Java was jdk-14.0.1 here, with this error.

Now removed VM args and tried jdk-19.0.2 - yes, solved, the national error text is visible ! Thanks, Erel !

But
1) How to make EN output of the log messages?
2) Now i indeed do not understand what's wrong with the file creation (copying from the stream): (Syntax error in file name, folder name, or volume label)
And URL and path are fully ASCII. Path is writeable ...
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
File name error is solved (it was 0x0D byte at the file name end), but the main topic question is not solved - how to override the Java log output language, just make it always english, at any PC locale language.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
File name error is solved (it was 0x0D byte at the file name end), but the main topic question is not solved - how to override the Java log output language, just make it always english, at any PC locale language.
Try this. see what it is?
B4X:
Dim jo As JavaObject
'jo.InitializeStatic("java.util.Locale").RunMethod("setDefault", Array(jo.GetField("US")))
Log(jo.InitializeStatic("java.util.Locale").RunMethod("getDefault", Null))
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User

This code:
Sub AppStart (Form1 As Form, Args() As String)
    Dim jo As JavaObject
    Log(jo.InitializeStatic("java.util.Locale").RunMethod("getDefault", Null))
    jo.InitializeStatic("java.util.Locale").RunMethod("setDefault", Array(jo.GetField("US")))
    Log(jo.InitializeStatic("java.util.Locale").RunMethod("getDefault", Null))

...gives:
WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
ru_RU
en_US

But it did not help with the log error messages language. Now the root error is fixed and no error message.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
But it did not help with the log error messages language. Now the root error is fixed and no error message.
I have said that in post #2, I guess your windows language is RU, you need to set it up to EN in system Setting
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Used the environment variable JAVA_TOOL_OPTIONS to set permanently:
-Duser.variant=US -Dnative.encoding=UTF-8 -Duser.country=US -Duser.language=en -Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8

Locale was changed, but ...
1) I have found the error message garbled characters are of "Cp1251" encoding page that is assigned to Java settings "native.encoding" and "sun.jnu.encoding"...
2) ... and these 2 settings cannot be changed by commands !!11 :(
Just not changed and that's it.

It was some Java bug fix about it in Java18, but in my Java 19 it does not work any way :)
It seems, changing is impossible ...
 
Upvote 0
Top