Set control to visible false

Hi,

i try to set the visible my button to false, but it doesn’t working. Can somebody help me please?
<panel width=“100%” height=“15%” align=“center” valign=“center” childLayout=“horizontal” marginTop=“20px”>
<control id=“startRaceButton” visible=“true” type=“button” label=“start a race” >
<interact onClick=“submitStartRace()” />
</control>
<control id=“cancelButton” type=“button” label=“cancel” >
<interact onClick=“submitCancel()” />
</control>
</panel>[/java]
in Controller:
[java]screen.findElementByName(ScreenConst.STARTRACEBUTTON).setVisible(false); [/java]

i try too with hide:
[java]screen.findNiftyControl(ScreenConst.STARTRACEBUTTON, Button.class).getElement().hide();[/java]
but nothing happens.

i get this fould:
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker callMethod
WARNING: Exception: java.lang.reflect.InvocationTargetException
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: sun.reflect.NativeMethodAccessorImpl invoke0 (NativeMethodAccessorImpl.java:-2)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: sun.reflect.NativeMethodAccessorImpl invoke (NativeMethodAccessorImpl.java:57)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: sun.reflect.DelegatingMethodAccessorImpl invoke (DelegatingMethodAccessorImpl.java:43)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: java.lang.reflect.Method invoke (Method.java:601)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.NiftyMethodInvoker callMethod (NiftyMethodInvoker.java:145)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.NiftyMethodInvoker performInvoke (NiftyMethodInvoker.java:104)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.Nifty$DelayedMethodInvoke perform (Nifty.java:1174)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.Nifty invokeMethods (Nifty.java:1152)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.Nifty handleDynamicElements (Nifty.java:354)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.Nifty access$1700 (Nifty.java:77)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl processEvent (Nifty.java:1374)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl processMouseEvent (Nifty.java:1329)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.niftygui.InputSystemJme handleMouseEvent (InputSystemJme.java:124)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.niftygui.InputSystemJme onMouseButtonEventQueued (InputSystemJme.java:197)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.niftygui.InputSystemJme forwardEvents (InputSystemJme.java:261)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.Nifty update (Nifty.java:288)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.niftygui.InputSystemJme endInput (InputSystemJme.java:113)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.input.InputManager processQueue (InputManager.java:818)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.input.InputManager update (InputManager.java:882)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.app.Application update (Application.java:604)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.app.SimpleApplication update (SimpleApplication.java:231)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.system.lwjgl.LwjglAbstractDisplay runLoop (LwjglAbstractDisplay.java:151)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.system.lwjgl.LwjglDisplay runLoop (LwjglDisplay.java:185)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.system.lwjgl.LwjglAbstractDisplay run (LwjglAbstractDisplay.java:228)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: java.lang.Thread run (Thread.java:722)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: Root Cause: java.lang.NullPointerException
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.oriam.client.screens.ScreenManager submitReady (ScreenManager.java:119)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: sun.reflect.NativeMethodAccessorImpl invoke0 (NativeMethodAccessorImpl.java:-2)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: sun.reflect.NativeMethodAccessorImpl invoke (NativeMethodAccessorImpl.java:57)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: sun.reflect.DelegatingMethodAccessorImpl invoke (DelegatingMethodAccessorImpl.java:43)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: java.lang.reflect.Method invoke (Method.java:601)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.NiftyMethodInvoker callMethod (NiftyMethodInvoker.java:145)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.NiftyMethodInvoker performInvoke (NiftyMethodInvoker.java:104)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.Nifty$DelayedMethodInvoke perform (Nifty.java:1174)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.Nifty invokeMethods (Nifty.java:1152)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.Nifty handleDynamicElements (Nifty.java:354)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.Nifty access$1700 (Nifty.java:77)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl processEvent (Nifty.java:1374)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl processMouseEvent (Nifty.java:1329)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.niftygui.InputSystemJme handleMouseEvent (InputSystemJme.java:124)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.niftygui.InputSystemJme onMouseButtonEventQueued (InputSystemJme.java:197)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.niftygui.InputSystemJme forwardEvents (InputSystemJme.java:261)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: de.lessvoid.nifty.Nifty update (Nifty.java:288)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.niftygui.InputSystemJme endInput (InputSystemJme.java:113)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.input.InputManager processQueue (InputManager.java:818)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.input.InputManager update (InputManager.java:882)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.app.Application update (Application.java:604)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.app.SimpleApplication update (SimpleApplication.java:231)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.system.lwjgl.LwjglAbstractDisplay runLoop (LwjglAbstractDisplay.java:151)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.system.lwjgl.LwjglDisplay runLoop (LwjglDisplay.java:185)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: com.jme3.system.lwjgl.LwjglAbstractDisplay run (LwjglAbstractDisplay.java:228)
Dez 16, 2013 11:25:48 PM de.lessvoid.nifty.NiftyMethodInvoker logException
WARNING: java.lang.Thread run (Thread.java:722)

Thank for helping. [java][/java]

For interact callbacks, Nifty uses reflection, which can be tricky to get working.

Please check how submitStartRace() and submitCancel() are declared. Are they public methods of a public class? If not, Nifty (which is in another package) will be unable to invoke them using reflection.

Hi,

this method are public of a public class

I use the method hide, but it looks like you may be calling it in a weird way. I use:

[java]screen.findElementByName(“myElementId”).hide(); [/java]

As long as your findElementByName retrieves the right element that should work. However, it can be a little temperamental if you attempt to hide the element before the screen is loaded.

As far as your exception goes… you didn’t show where you define the control in your xml so its not very clear what is causing that exception but it doesn’t have to do with attempting to hide the element.

You have a nullpointerexception in the stacktrace, make sure that your variable “screen” is correctly initialized (use some println). actually, when you have a problem like that you should try to don’t use this kind of “method chaining” and, instead, print every step to make sure you reach it and that everything is correctly initialized.

Also, remember that the bind method is NOT call immediatly after the setscreen (i have about 0.3 second between the setscreen and the bind) and that the startscreen is called later (i have about 1.3 s)