The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: java.lang.NullPointerException

So when I run your code with the main() method tucked into the Scanner class, I get:

Exception in thread "main" java.lang.NullPointerException
at Survey.enterQuestions(Survey.java:22)
at Survey.main(Survey.java:48)

Note that the complaint is caused by the call to method enterQuestions() and the line specifically to the NPE is:

for (int i = 0; i < Questions.length; i++)

What in that line could be null? Well, it's fairly obvious that it can only be Questions.length. Why is that? Well, Questions is declared as an instance variable, but it is never initialized. It's a container into which nothing has been placed.

I doubt this code is exactly the same as you had before. Check the Survey() constructor and see if there's code missing there. If not there, then the code is missing from the enterQuestions() method. No matter where it's missing, the Questions[] array must be initialized to be used.