In an application associated with a previous question I want the user to be able to save the configuration of some their settings, such as the colour of areas of the UI and then be able to recall that configuration.
I have saved the fill color of the particular rectangles to a file using the following code:
config.ini contains:
0x000000ff
0x000000ff
0x0c0099ff
0x666666ff
0x666666ff
Rin
0x086600ff
Vis
0x086600ff
0x000000ff
Note that Rin and Vis are not color values, but text values for labels that I can handle OK.
But I can't find the correct method to set the rectangle fill color after reading the values from the file. The basis of the code I've tried is:
But it throws the following error:
Error occurred on line: 257 (main).
java.lang.NumberFormatException: For input string: "0x000000ff"
at sun.misc.FloatingDecimal.parseHexString(FloatingDecimal.java:2071)
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1870)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at b4j.example.main._btnloadconfig_action(main.java:390)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:563)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:221)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at anywheresoftware.b4a.BA$2.run(BA.java:165)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/21665305.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/17230114.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/2180324.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
What should Array(fx.Colors.From32Bit(line)) be instead so it correctly consumes the color specified as a string in the form 0x000000ff?
Thanks in anticipation of some suggestions.
Bryon
I have saved the fill color of the particular rectangles to a file using the following code:
B4X:
Dim tw As TextWriter
tw.Initialize(File.OpenOutput(File.dirapp, "config.ini", False))
Dim clr As String
Dim joRect As JavaObject = RinScoreRect
clr = joRect.RunMethod("getFill",Null)
tw.WriteLine(clr)
config.ini contains:
0x000000ff
0x000000ff
0x0c0099ff
0x666666ff
0x666666ff
Rin
0x086600ff
Vis
0x086600ff
0x000000ff
Note that Rin and Vis are not color values, but text values for labels that I can handle OK.
But I can't find the correct method to set the rectangle fill color after reading the values from the file. The basis of the code I've tried is:
B4X:
Dim tr As TextReader
tr.Initialize(File.OpenInput(File.dirapp, "config.ini"))
Dim line As String
Dim row As Int = 0
line = tr.readline
Do While line <> Null
Select row
Case 0
Dim joRect As JavaObject = RinScoreRect
joRect.RunMethod("setFill", Array(fx.Colors.From32Bit(line)))
But it throws the following error:
Error occurred on line: 257 (main).
java.lang.NumberFormatException: For input string: "0x000000ff"
at sun.misc.FloatingDecimal.parseHexString(FloatingDecimal.java:2071)
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1870)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at b4j.example.main._btnloadconfig_action(main.java:390)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:563)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:221)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at anywheresoftware.b4a.BA$2.run(BA.java:165)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/21665305.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/17230114.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/2180324.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
What should Array(fx.Colors.From32Bit(line)) be instead so it correctly consumes the color specified as a string in the form 0x000000ff?
Thanks in anticipation of some suggestions.
Bryon