• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

java.lang.NullPointerException

 
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>




 
Ranch Hand
Posts: 344
Oracle Java Linux
  • 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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • 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
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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 Windows XP Java
  • 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
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
 
Rancher
Posts: 1041
6
  • 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.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic