Search code examples
javajavafxparseint

How to fix java.lang.reflect.InvocationTargetException when using integer.parseint


Im trying to make a simple calculation program but i keep getting this error whenever I try to run the code. How can i avoid this?

TextField inputOne = new TextField("Input first data");


        // Making output 1
        int inputNumber = Integer.parseInt(inputOne.getText());

Always get error message java.lang.reflect.InvocationTargetException at line 25 where the parse int is placed


Solution

  • getText() function returns the input value of the user, or the "Input first data" String? if it returns the input value of the user then it is probably a NumberFormatException that you should handle, else it is because the String mentioned is the mistake.