If you check the API docs for Scanner.nextLine(), you'll see that when there is no line found, it doesn't return null - it throws an exception. You should use Scanner.hasNextLine() before nextLine()...