Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why does this crash

 
Jeffrey Chu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i get a java.lang.nullpointerexception
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the EXACT error message. It contains a LOT of information that can help us help you track down the problem.

Layne
 
Jeffrey Chu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


sry about that im new here
[ May 01, 2005: Message edited by: Jeffrey Chu ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Typo. Should be "word2 = ". Since word2 is null when you call add(), you get a NullPointerException. That stack trace says the error happens at line 28 in your applet; so you look at line 28, and figure out what's wrong.
[ May 01, 2005: Message edited by: Ernest Friedman-Hill ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem. Let's analyze what the error message says.

The first line indicates that your program threw an NullPointerException (which you obviously already knew). The next line starts what is called the "call stack". This is the chain of method calls that lead up to the exception. The first line tells you that this exception was thrown from java.awt.Container.addImpl() which is in the standard Java API. Notice that it also indicates the source file name and line number. If you want to, you can look at the source code that comes with the JDK. At this point, we probably just want to find the problem with your own code, so let's continue. The next line tells you that Container.addImpl() was called from Container.add() which is again a method from the Java API. The third line finally gives us a method in your own code: Pretty.init(). Container.add() was called on line 28 in Pretty.java. So now what is line 28?

Well, it looks like I took to long to finish typing my response. EFH has already given you some more information. However, I thought I'd still submit my post so that you can understand the information that the error message gives you and hopefully track down these kinds of errors on your own next time.

Keep Coding!

Layne
[ May 01, 2005: Message edited by: Layne Lund ]
 
Jeffrey Chu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
o wow... now i feel stupid... thanks guys for your input
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic