aspose file tools*
The moose likes Servlets and the fly likes getting nullpointer exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "getting nullpointer exception" Watch "getting nullpointer exception" New topic
Author

getting nullpointer exception

syed mahboob
Greenhorn

Joined: Dec 06, 2012
Posts: 15




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

Joined: Jan 10, 2002
Posts: 61010
    
  65

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
syed mahboob
Greenhorn

Joined: Dec 06, 2012
Posts: 15
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

Joined: Jan 10, 2002
Posts: 61010
    
  65

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

Joined: Dec 10, 2012
Posts: 13

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();


“Anyone who has never made a mistake has never tried anything new.” ― Albert Einstein
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

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

Joined: Dec 06, 2012
Posts: 15
Sir i am trying to attach file but it is neither accepting .txt file nor .java file.How can I attach?
gurunath pai
Greenhorn

Joined: Dec 10, 2012
Posts: 13


@Bear Bibeault : It is correct what you said, I just gave him a alternate solution to his problem.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 510

Gurunath/Syed,

Please see this, UseTheForumNotEmail.

Regards, Prasad
SCJP 5 (93%)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

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

Joined: Jul 16, 2012
Posts: 136
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

Joined: Jan 10, 2002
Posts: 61010
    
  65

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

Joined: Dec 18, 2012
Posts: 1
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting nullpointer exception