jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes Runtime Error in Program for Unknown Reasons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Runtime Error in Program for Unknown Reasons" Watch "Runtime Error in Program for Unknown Reasons" New topic

Runtime Error in Program for Unknown Reasons

Jacob Steingart
Ranch Hand

Joined: Mar 28, 2008
Posts: 63
I typed this up myself from Head First Java. I keep getting a NullPointerException that says the following:

Exception in thread "main" java.lang.NullPointerException
at QuizCardPlayer.go(QuizCardPlayer.java:27)
at QuizCardPlayer.main(QuizCardPlayer.java:19)

I didn't see anything blatently wrong with the code I had written, and the problem appeared to be in my first two methods, but it starts up the same way as some other programs of mine that work fine. Here is the code, cut and pasted fresh from jGrasp.

If someone could scan this over or if they know that I made some stupid mistake (I haven't done GUI in awhile, I'm still getting back into the swing of things, no pun intended) I would be immensley thankful.
[ June 04, 2008: Message edited by: Rob Prime ]

I never know what to put in my signature...
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

The top line from the stack trace in the error message

at QuizCardPlayer.go(QuizCardPlayer.java:27)

means that the error happens at line 27 of this file. Use your editor to figure out what line that is. A NullPointerException on a particular line always means that something to the left of a dot ('.') or left-brace ('[') is null. Find out what variable on that line might be null, then try to figure out where its value should have been set, and you'll have solved the problem.

[Jess in Action][AskingGoodQuestions]
Jacob Steingart
Ranch Hand

Joined: Mar 28, 2008
Posts: 63
Aha! I was stupid and forgot to declare the JTextArea... now it works!
I agree. Here's the link: http://aspose.com/file-tools
subject: Runtime Error in Program for Unknown Reasons
Similar Threads
New Quiz Card Builder/Player for Exam Study
QuizCard class not found. (Head First Java 2nd Ed)
Head First Java QuizCardBuilder not saving files correctly
HeadFirst >>Chapter14:ArrayList Error
Problem reading JTextArea