The code does not compile, so your compiler will give you an error message, which should be fairly self explanatory, including a line number pointing to the line on which the error occurs (something like: can't assign String to int for example).
–
assyliasAug 15 '12 at 10:05

6 Answers
6

ageTxt.getText() returns a java.lang.String. You are trying to assign that to an primitive int That will not work.

You can use Integer.parseInt() to convert a String to an int. But note that this might throw a NumberFormatException when the string is not a valid number. So you might want to wrap it in a try-catch block.

ageTxt.getText() returns a String object containing the characters typed by the user, and you try to put it in a int var, which can only contain integers. So it can't work. Just put it in a String object, then parse it to get the integer value by doing Integer.parseInt(myStringObject). Be careful this can throw an exception if the String object doesn't contains an integer number.