I have a program that calculates a value based on user input, and currently I have the greenfoot.ask in the constructor. everything works fine if i drop the calculator class into the world, but if I try to save the world, it will not compile and i get java.lang.NumberFormatException: null. Here is the code constructor code for the calculator (this isn't all of the calculator code just what relates to the constructor):
I have tried a few things like assigning greenfoot.ask to a variable and the parsing that variable and i got the same result.
1 2 3 4 5 6 7 8 | int startingNumber = 1 ; List<Integer> steps = new ArrayList<Integer>(); public Calculator() { steps.add(Integer.parseInt(Greenfoot.ask( "enter a number >0 (preferably <1000 too and dont do anything rediculous like 9999....)" ))); GreenfootImage startingNumber = new GreenfootImage( "Starting Number: " + steps.get( 0 ), 40 , Color.WHITE, Color.BLACK); setImage(startingNumber); } |