wood burning stoves 2.0*
The moose likes Servlets and the fly likes Resolve 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 » Servlets
Bookmark "Resolve NullPointerException" Watch "Resolve NullPointerException" New topic
Author

Resolve NullPointerException

Singh Anisha
Ranch Hand

Joined: May 09, 2012
Posts: 100




Throwing following exception
type Exception report

message

description The server encountered an internal error that prevented it from fulfilling this request.

exception

java.lang.NullPointerException
LogIn.doPost(LogIn.java:21)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41046
    
  43
Please edit your post to UseCodeTags, then indicate to us which line is line 21, and also tell us which object is null.

What are the "toString()" calls supposed to accomplish for username and password?

Strings are not compared using the "==" operator, but using the "equals" method.

The DB query won't work because you're using the string "username" where you should be passing in the value of the "username" variable. Read up on PreparedStatement on how to do that.


Ping & DNS - my free Android networking tools app
Singh Anisha
Ranch Hand

Joined: May 09, 2012
Posts: 100

String username=request.getParameter("username");

Here to fetch form field data of username, and then put it to variable username.

Exception is thrown at line 15 of above code.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41046
    
  43
Exception is thrown at line 15 of above code.

That seems unlikely. The only object that could cause such an exception would be "response" - which was NOT null in line 14.
Singh Anisha
Ranch Hand

Joined: May 09, 2012
Posts: 100

i rearranged the codes and find problem is in SQLpart


Now browser displaying...
Query problem
Failed..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41046
    
  43
Use out.write("Query Problem: "+e.getMessage()) instead so that you'll know what the problem actually is.
Singh Anisha
Ranch Hand

Joined: May 09, 2012
Posts: 100

Illegal operation on empty result set.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

That's right, you do need to consider the possibility that your query will return zero records. You should call the "rs.next()" method before trying to use any data from the first row -- after all, there might not be one. The "next" method will tell you that.
Singh Anisha
Ranch Hand

Joined: May 09, 2012
Posts: 100

Thanks to all of you. Finally now no exceptions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Resolve NullPointerException
 
Similar Threads
login page in struts - please help
Can not establish connection
small problem with query
jdbc connectivity of sql server
year getting null?