• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting nullpointer exception

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




i am getting this errror..



HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

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

exception

java.lang.NullPointerException
com.lara.login.LoginDAO.authenticateUser(LoginDAO.java:29)
com.lara.login.LoginAction.process(LoginAction.java:21)
com.lara.servlets.controller.ControllerServlet.doPerform(ControllerServlet.java:108)
com.lara.servlets.controller.ControllerServlet.doPost(ControllerServlet.java:86)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.28 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.28
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's telling you which line has the problem:

java.lang.NullPointerException
com.lara.login.LoginDAO.authenticateUser(LoginDAO.java:29)


So, what do you think your next step should be?
 
syed mahboob
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i dont now thats why i am asking? what should i have to change in line 29 please tell me?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only way that line can NPE is if con is null. You'll need to backtrack and find out why null is being passed to the method.
 
Greenhorn
Posts: 13
Android Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here stmt = con.createStatement(); the con object is having the value null, you can check this by debugging your application. At run time it happens something like this null.createStatement() which is false. I can help if you attached all the Files related to it (LoginDAO.java , LoginAction.java).


String connectionURL = "jdbc:postgresql://localhost:5432/cities";
// Change the connection string according to your db, ip, username and password
String username="postgres";
String password="admin@123";

Class.forName("org.postgresql.Driver");
// If you are using any other database then load the right driver here.

//Create the connection using the static getConnection method
con = DriverManager.getConnection (connectionURL,username,password);

add this lines before

con.createStatement();

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurunath pai wrote:add this lines before


No. The connection is passed to the method. It would be foolish to try and establish the connection inside the method.
 
syed mahboob
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sir i am trying to attach file but it is neither accepting .txt file nor .java file.How can I attach?
 
gurunath pai
Greenhorn
Posts: 13
Android Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

@Bear Bibeault : It is correct what you said, I just gave him a alternate solution to his problem.
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gurunath/Syed,

Please see this, UseTheForumNotEmail.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurunath pai wrote:
@Bear Bibeault : It is correct what you said, I just gave him a alternate solution to his problem.


But not a good one. It will break the structure of the rest of the application.

The OP must find out why the caller of the method is passing null to the method.
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Syed,

Try adding classes.jar to your app. this might solve the problem as in case of me most of the jdbc programs give a null pointer exception, i add classes.jar and resolves.

Thanks
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is classes.jar? If a missing jar file is the OP's issue, we need a lot more info before trying to figure out what's missing. Most likely, the code that is trying to establish the connection is failing., We need to find out why before applying random guesses as to what is wrong.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason is the connection reference is getting null.
There is a problem with initializing the connection object.
Can you post the code where connection is initialized?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic