This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes NullPointerException 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 » Beginning Java
Bookmark "NullPointerException" Watch "NullPointerException" New topic
Author

NullPointerException

Phillipe Rodrigues
Ranch Hand

Joined: Oct 30, 2007
Posts: 165
What can be the exact cause of this below err?

java.lang.NullPointerException
at MVC.Example1.doGet(Example1.java:30)
at MVC.Example1.doPost(Example1.java:56)


Thanks,
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
What can be the exact cause of this below err?

java.lang.NullPointerException
at MVC.Example1.doGet(Example1.java:30)
at MVC.Example1.doPost(Example1.java:56)
--------------------

Thanks,



It would be difficult to answer your question without seeing your code. It seems that the reference variable is not initialized properly, but you have tried to access the methods associated with the reference. For example,


the above code snippet will throw NPE since str is not initialized.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Something in line 30 of Example1.java is null when it isn't supposed to be.

NullPointerExceptions are usually easy to solve - just look carefully at the line where the error occurs to see what could be null there.

Since you didn't post the source code, we can't tell you exactly what's wrong. So if you don't see it yourself, show us the code.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: NullPointerException
 
Similar Threads
package org.jdom does not exist
Where to save my .java files?
a very primitive problem
noob cp problems in webapp
compiling java with import package