B4J Question Java locale language in the IDE logs

peacemaker

Expert
Licensed User
Longtime User
Hi, All



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:

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



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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…