Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting nullpointer exception

 
syed mahboob
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
gurunath pai
Greenhorn
Posts: 13
Android Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator

@Bear Bibeault : It is correct what you said, I just gave him a alternate solution to his problem.
 
Prasad Krishnegowda
Ranch Hand
Posts: 665
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gurunath/Syed,

Please see this, UseTheForumNotEmail.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Jahir Saiyed
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic