Why did the program encounter a java.lang.nullpointerException error?