• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.NullPointerException

 
polavarapu prasad
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i try to execute it on server it shows java.lang.NullPointerException so please help me in solving this problem

thanks in advance
durga prasad


login html

<html>
<body bgcolor=lime>
<br><br><br>
<center>
<form method="POST" action="/connection/ServletConnection">
<pre>
user id :<input type="text" name="user" size="20">
password :<input type="password" name="pswd" size="20">
<input type="submit" name="login" value="signin"></pre>

</form>
</center>
</body>
</html>



ServletConnection servlet




web xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<servlet>
<servlet-name>Zulfiqar</servlet-name>
<servlet-class>ServletConnection</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Zulfiqar</servlet-name>
<url-pattern>/ServletConnection</url-pattern>
</servlet-mapping>
</web-app>




 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at your stacktrace and see which line number and class the exception originates from.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
remember it is always good practice to do null check before rs.next as in
 
Rob Spoor
Sheriff
Pie
Posts: 20750
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not necessary. Statement.executeQuery will never return null.

Polavarapu, are you sure that s3 and s4 will never be null?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:That's not necessary. Statement.executeQuery will never return null.


I dont know that. just referred the java doc. so far the projects i see, they do the null check, so i misunderstood.

thanks rob
 
Rob Spoor
Sheriff
Pie
Posts: 20750
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Javadoc is clear about never returning null, so any example that checks for null as a redundant null check.

And you're welcome of course
 
Ivan Jozsef Balazs
Rancher
Posts: 987
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A sidenote: it is not a good idea to declare these
as instance variables of the servlet.
A servlet instance might serve different requests in different threads.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic