Android Question error while setting locale to british format

Makumbi

Well-Known Member
Licensed User
Please help i wanted to set my app to British locale date and time settings but i get error below please help thanks
B4X:
    Dim jo As JavaObject
    jo.InitializeStatic("java.util.Locale").RunMethod("setDefault", Array(jo.GetField("en")))

B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
    
#End Region

Sub Process_Globals
    Public SQL1 As SQL
    Dim SQL1 As SQL
    'Dim cursor1 As Cursor
    Public Provider As FileProvider
    Dim cursor As Cursor
    Private nid As Int = 1
    Private serializator As B4XSerializator
    Dim SQLDataBasePath = File.DirInternal As String
    Dim SQLDateBaseName = "studentdbmk.sql" As String
    'Dim SQLTabelName = "persons" As String
    Public CurrentIndex As Int        'index of the current entry
    Public RowNumber As Int                'number of rows
    Public rp As RuntimePermissions
    Public IDList As List        'list containing the IDs of the database
    'we need it because the IDs can be different from the list indexes
    'if we delete an entry its ID is lost
    Dim cursor As Cursor
    'Variables for Edit
    'the Edit Activity has two modes  "Add"  and "Edit"
    Public EditMode As String

    Type StudentData (Studentnamed As String, LblCity As String,Classr As String, Stream As String, Subject As String, Termr As String,City As String, Latitude As Float, Longitude As Float, Altitude As String,Totalmarks As String,English As String,Maths As String,Science As String,Sst As String,ire As String,Lit1 As String,Lit2 As String,Totalgrade As String,Division As String,iregrade As String,sciencegrade As String,sstgrade As String,mathsgrade As String,engrade As String)

    'Variables for Filter
    'variable for the filter query,
    'defined in the btnFilter_Click routine
    'and will be used In the DBWebView ShowTable routine
    Public FilterQuery As String
    
    'flag for the filter active or inactive
    Public flagFilterActive As Boolean
    
    'Boolean operator used in the filter
    'can be OR or AND
    Public FilterBooleanOperator As String
    
    'Variables used to hold the selected indexes of the Spinners
    Public SelectedFirstName = 0 As Int
    Public SelectedLastName = 0 As Int
    Public SelectedCity = 0 As Int
    Dim strTitle As String
    Dim strBody As String
    
End Sub
Private Sub CreateMessage(Body As String) As Byte()
    Dim m As Message
    m.Initialize
    m.Body = Body
    m.From = "currentName"
    Return serializator.ConvertObjectToBytes(m)
End Sub
Public Sub SendMessage(Body As String)
    CreateMessage(Body)
    'client.Publish2("all", CreateMessage(Body), 0, False)

End Sub
Sub Service_Create
    'initialize the variables
    Provider.Initialize
    CurrentIndex = -1
    RowNumber = 0
    EditMode = "Add"
    FilterQuery = ""
    flagFilterActive = False
    FilterBooleanOperator = "OR "
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
    'File.Delete(File.DirInternal, "studentdbm.sql") ' only for testing, removes the database
    'check if the database already exists
    Dim jo As JavaObject
    jo.InitializeStatic("java.util.Locale").RunMethod("setDefault", Array(jo.GetField("en")))
    If File.Exists(SQLDataBasePath, SQLDateBaseName) = False Then
        'copy the default DB
        File.Copy(File.DirAssets, SQLDateBaseName, SQLDataBasePath, SQLDateBaseName)
        'if not, initialize it
        SQL1.Initialize(SQLDataBasePath, SQLDateBaseName, True)
        'and create it
        'CreateDataBase
        SQLInit
        
    
        

        CallSubDelayed(Firebasemessaging, "SubscribeToTopics")
    
    Else
    
    
        SQL1.Initialize(SQLDataBasePath, SQLDateBaseName, True)
        'SQLInit
        CallSubDelayed(Firebasemessaging, "SubscribeToTopics")

B4X:
    at android.app.ActivityThread.access$1300(ActivityThread.java:199)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1666)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
** Service (starter) Start **
Using FileProvider? true
Error occurred on line: 77 (Starter)
java.lang.RuntimeException: Field: en not found in: java.util.Locale
    at anywheresoftware.b4j.object.JavaObject$FieldCache.getField(JavaObject.java:306)
    at anywheresoftware.b4j.object.JavaObject.GetField(JavaObject.java:181)
    at com.kccug.kabojjajuniorapp.starter._service_create(starter.java:345)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at com.kccug.kabojjajuniorapp.starter.onCreate(starter.java:56)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3532)
    at android.app.ActivityThread.access$1300(ActivityThread.java:199)
 

OliverA

Expert
Licensed User
Longtime User
Upvote 0

Makumbi

Well-Known Member
Licensed User
Looking at developer docs ( https://developer.android.com/reference/java/util/Locale#US), you’re looking at either ENGLISH or US for the field names to get (they need to be in all caps). en is not an option.

i tried setting it to UK and it appears to be running without any error is it ok to maintain it like that thanks
B4X:
    Dim jo As JavaObject
    jo.InitializeStatic("java.util.Locale").RunMethod("setDefault", Array(jo.GetField("UK")))
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
i tried setting it to UK and it appears to be running
UK is actually there in the documentation. So yes, you should be fine.
 
Upvote 0
Top