[SOLVED] Simple update label text in controller

Apologies if this is a dumb question.
But im trying to update a simple text label but no luck.
There is no error reported, but it doesnt update to “Mum”. :frowning:
If i do it onStartScreen it NPE.

<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd">
	<!-- +++++++++++++++++++++++++++++++++++++++ -->
	<!-- load default styles and controls -->
	<!-- +++++++++++++++++++++++++++++++++++++++ -->
	<useStyles filename="nifty-default-styles.xml" />
	<useControls filename="nifty-default-controls.xml" />
	<style id="console-red" base="button-font">
		<attributes font="fonts/menu.fnt" color="#f00f" />
	</style>
	<style id="console-white" base="button-font">
		<attributes font="fonts/menu.fnt" color="#ffff" />
	</style>
	<style id="console-font">
		<attributes font="fonts/verdana-48-regular.fnt" color="#00ff" />
	</style>

	<!-- +++++++++++++++++++++++++++++++++++++++ -->
	<!-- messages view -->
	<!-- +++++++++++++++++++++++++++++++++++++++ -->

	<screen id="start" controller="julius.sky.voicehud.core.hud.MessagesController" width="60%" height="60%">
		<layer id="HUDGUI" childLayout="center" backgroundColor="#0000" visible="true" width="60%" height="60%">
         	<panel childLayout="vertical" width="50%" height="100px" backgroundColor="#0f08">
			</panel>
	    </layer>
		<layer id="MESSAGES" childLayout="center" backgroundColor="#0000" visible="true" width="60%" height="60%">
					<image filename="Interface/images/mum.png" childLayout="overlay" width="70" height="50"/>
		  	   		<control name="label" id = "nameLabel1" text="name" color="#0f88"
					align="center" valign="top" height="50px" >
		<!-- 							font="Interface/Fonts/Arial32px.fnt">-->						
					</control>
					<control name="label" id = "messageLabel1" text="hello" color="#0f88"
					align="center" valign="center" height="50px" >
		<!-- 							font="Interface/Fonts/Arial32px.fnt">-->						
					</control>
		</layer>
		
	</screen>

</nifty>




public class MessagesController extends SimpleApplication implements ScreenController{
	
	private HUDGUI hudGUI;
	private Nifty nifty;
	private Screen screen;

	/**
	 * Creates a new controller instance for nifty-gui.
	 */
	public MessagesController(HUDGUI hudGUI) 
	{
//		this.sim = sim;
		this.hudGUI = hudGUI;
		this.nifty = hudGUI.getNifty();
		this.screen = nifty.getCurrentScreen();
	}

	public void bind(Nifty arg0, Screen arg1) {
		// TODO Auto-generated method stub
		
	}

	public void onEndScreen() {
		// TODO Auto-generated method stub
		
	}

	public void onStartScreen() {
		// TODO Auto-generated method stub
		
//		TextRenderer nameLabel = screen.findElementByName("MESSAGES").
//				findElementByName("namelabel").getRenderer(TextRenderer.class);
//		nameLabel.setText("Mum");
		//setTextToElement("control.id", "text")
//		setTextToElement("nameLabel", "Mum");
//		setTextToElement("namelabel1", "Mum");

	}
	
	/**
	 * Sets given text to the given element (e.g. label).
	 * 
	 * @param elementID
	 * 			Element's ID to assign a text to.
	 * 
	 * @param text
	 * 			Text to set.
	 */
    private void setTextToElement(String elementID, String text) 
    {
    	getElementByID(elementID).getRenderer(TextRenderer.class).setText(text);
    }
    
    /**
     * Looks up an element by ID.
     * 
     * @param elementID
     * 			ID to  look up.
     * 
     * @return
     * 			Element with given ID.
     */
    private Element getElementByID(String elementID)
    {
    	return nifty.getCurrentScreen().findElementByName(elementID);
    }

	@Override
	public void simpleInitApp() {
		// TODO Auto-generated method stub
//		setTextToElement("nameLabel1", "Mum");

		
	}
	
	 @Override
	 public void simpleUpdate(float tpf) {
		 
			setTextToElement("nameLabel1", "Mum");

	 }
    

}

oops. it nped in the another controller.
it works onStartScreen.
How to mark as resolved? or just delete for trivial overlook?

I seemed to have rights, I edited the topic header for you. Hope you don’t mind.