I am getting java.lang.NullPointerException and don't know exactly what is causing it. I know it has something to do with my getInput method, but I don't which line or lines is causing the error. Any help would be appreciated.
public class Input {
private Scanner scan;
//Checks input is an integer and bigger than 1
public int getInput() {
String input = scan.next();
int number = 0;
boolean isNumber = true;
while(isNumber) {
try {
number = Integer.parseInt(input);
if(number >= 1) {
isNumber = false;
}
} catch (NumberFormatException e) {
isNumber = true;
System.out.println("Error: please enter a whole number that is bigger than 1");
input = scan.next();
}
}
return number;
}
}
public class Main {
public static void main (String[] args) {
Input userInput = new Input();
System.out.println("\t" +"Collatz Conjecture");
System.out.println("Please enter a value: ");
int n;
n = userInput.getInput();
System.out.println("Your number is " + n);
}
}