Nifty getting int value


How I can get int value of variable in my java controller class? I tried smth like that but doesn’t work:
[java] <panel id=“loadingtextPanel” height="${PROP.centerX}" width="${PROP.centerY}" childLayout=“center”>[/java]

At a base level I think height and width are string properties because they can be parsed into different values such as pixels or percentages. So I imagine what you would want to do is set your centerX and centerY variables as strings like the following:

[java]String centerX = myIntVariable + “px”;[/java]

1 Like

I changed that but now get: [java]Caused by: java.lang.NumberFormatException: For input string: “${PROP.centerX}”[/java]

tried also: centerX = Integer.toString(game.getX()) + “px”;

In game class i get it by:
[java] x = Display.getWidth()/2;
y = Display.getHeight()/2;[/java]

I also tried using method in my ScreenController class getX() , getY() and in GUI.xml ${CALL.getY()}, ${CALL.getX()} but still error

I belive that when you retrive the value nifty gives you the “not converted” string : " ${PROP.centerX} . try :
string newval = nifty.specialValuesReplace(yourstring);
int myInt = Integer.parseInt(newval);

hope it helps :wink: