B4J Question [SOLVED] Problem with the color property in the Custom Class

Star-Dust

Expert
Licensed User
Longtime User
I created a Custom Class and I entered this Property
B4X:
#DesignerProperty: Key: ColorBase, DisplayName: Background Color, FieldType: Color, DefaultValue: 0xFF000000, Description: Color of background

Private ColorBase As Int
When I get to this statement the App crashes
B4X:
If Props.ContainsKey("ColorBase") Then ColorBase=Props.Get("ColorBase")
This is the mistake, it seems I can not do the casting ... I'm missing something ..
Waiting for debugger to connect...
Program started.
Errore nella linea: 40 (B4XSeekBar)
java.lang.NumberFormatException: For input string: "0xaaaaaaff"
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 anywheresoftware.b4a.BA.ObjectToNumber(BA.java:394)
at b4j.example.b4xseekbar._designercreateview(b4xseekbar.java:108)
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:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:628)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
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:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4j.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:62)
at anywheresoftware.b4j.objects.LayoutBuilder.loadLayout(LayoutBuilder.java:93)
at anywheresoftware.b4j.objects.PaneWrapper.LoadLayout(PaneWrapper.java:84)
at b4j.example.main._appstart(main.java:87)
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:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:628)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
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:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.start(main.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
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$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
 

Star-Dust

Expert
Licensed User
Longtime User
Found the solution alone: :D
B4X:
If Props.ContainsKey("ColorBase") Then ColorBase= xui.PaintOrColorToColor(Props.Get("ColorBase"))
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You don't need to check whether the property exists.

If the class was not used yet by other developers then you can assume that the property exists. During development you will need to click on the view in the designer to force the new property to appear.

If you are updating an existing class then use Props.GetDefault and get the default color if it doesn't exist.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
You don't need to check whether the property exists.

If the class was not used yet by other developers then you can assume that the property exists. During development you will need to click on the view in the designer to force the new property to appear.

If you are updating an existing class then use Props.GetDefault and get the default color if it doesn't exist.
You're right @Erel, you told me several times, but I always forget it and keep doing as I learned, like a mule that always repeats the path that he learned the first time.

Thanks for the help
 
Upvote 0
Top