Bug? Button Images are not initialized properly

jmon

Well-Known Member
Licensed User
Longtime User
Hello,

I may have found a bug. When I set an image on to a button in the Designer, and then I want to set the image in the IDE, I get an error:

B4X:
Program started.
main._appstart (java line: 52)
java.lang.RuntimeException: Object should first be initialized (ImageView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:28)
    at anywheresoftware.b4j.objects.ImageViewWrapper.SetImage(ImageViewWrapper.java:70)
    at b4j.example.main._appstart(main.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at b4j.example.main.start(main.java:33)
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:216)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
    at java.lang.Thread.run(Thread.java:744)

The only way to set the image currently is through the Designer.

Thanks.
 

Attachments

  • ButtonImages.zip
    7.1 KB · Views: 292

Erel

B4X founder
Staff member
Licensed User
Longtime User
ImageViews inside buttons are currently not supported. You can use JavaObject to get a reference to the internal "graphic" node:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("Main") 'Load the layout file.
   MainForm.Show
   Dim btnJO As JavaObject = btn
   imgButton = btnJO.RunMethod("getGraphic", Null)
   imgButton.SetImage(fx.LoadImage(File.DirAssets, "Icon.png"))
End Sub

Note that you can also set the image with CSS. This will allow you to use different images for the different states.
 
Top