aspose file tools*
The moose likes Servlets and the fly likes How to resolved the given error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to resolved the given error?" Watch "How to resolved the given error?" New topic
Author

How to resolved the given error?

Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
Hello all,

Kindly help me out in this,what should i do ,to resolved this error.


Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

Mohini Dhanaskar wrote:

Well, that looks like it's the cause. You need to look at that line of the code and work out what might be throwing a NullPointerException there.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 537

What's there in line 34 of ConsumerRegistrationServlet.java? Something in this line, is throwing a NullPointerException.
You just show us the exception and not the code, please post the code if possible...
Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
Sir, this is the code.



Anurag Verma
Ranch Hand

Joined: Mar 30, 2012
Posts: 124

i am sure you have either modified the code or missed some lines to post.....i cant see anything at line 34 which could have a NullPointer. Please have a cross check..
Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
Please suggest me.
Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
Now the code showing the following error:


Shwetank Arya
Greenhorn

Joined: May 14, 2011
Posts: 3

Mohini Dhanaskar wrote:Sir you are right,

i again run the same code ,this time it's not displaying any error but
still while running whole project after feeding values and clicking submit button
it is not calling SuccessfulComplaintRegister.jsp and value is not going to the database
ConsumerRegistration table.

what should i do?


Hi,

what i understand with above is that-
1. your project gets compiled without errors.
2. You are able to send values through some form you have created and using submit button.
3. After 1 & 2 you get exceptions...

Can you please check your form declaration or any additional request parameters for any thing possibly missing or null.

Good Luck.
Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
Tried everything ,still not getting why i am getting Null Pointer Exception.
Anurag Verma
Ranch Hand

Joined: Mar 30, 2012
Posts: 124

check line 34 of ConsumerRegistrationServlet.java or post it here (just line 34 & nothing else please). it is getting generated from there.
Madhavi Subramaniam
Ranch Hand

Joined: Nov 24, 2011
Posts: 33
I think,In destroy method only you getting null pointer exception.

Have you established the jbdc connection properly?

It seems,when trying to close the connection. Its getting error.

If possible to debug your program, check the value of the variables con & ps.

whether it has values or null.



Thanks.








Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
i am again sending you the code.




and error is :

Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

Please put a condition for checking if ps is null or not before closing it in the destroy method.
See this


Thanks & Regards, Sumeet
SCJP 1.4, SCWCD 5, LinkedIn Profile
Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

The code you're posting doesn't exactly match the code that's been run. The error tells you that a NullPointerException is thrown on line 34 of ConsumerRegistrationServlet.java, in the destroy() method. However, in the code you posted line 34 is not part of the destroy() method. This could be because you've omitted some unimportant lines, but in that case you need to tell us which corresponds to line 34 of the actual code.

However, the destroy() method is simple enough to analyse anyway. Do you know what causes a NullPointerException? It happens when you try to call a method on (or similar) a reference that is null. There's only one line in destroy() that can possibly throw one directly:
The exception means that ps is null on this line. The simplest fix that would make the exception go away is to check for this before trying to close it.

But I think there are bigger problems, It's not clear to me why ps isn't local to the doPost() method. As things stand, your servlet is not thread safe, because you might have multiple threads trying to call the same PreparedStatement at the same time. You've got to be very careful using instance variables in servlets, and it's usually a bad idea.
Anurag Verma
Ranch Hand

Joined: Mar 30, 2012
Posts: 124

Why didn't you post that thing here ?? Guys she replied to a private message that line 34 was ps.close();. & about the solution, enclose this with a null check, like this -

Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
i again run the same code ,this time it's not displaying any error but
still while running whole project after feeding values and clicking submit button
it is not calling SuccessfulComplaintRegister.jsp and value is not going to the database
ConsumerRegistration table.
Anurag Verma
Ranch Hand

Joined: Mar 30, 2012
Posts: 124

if(btnSubmit.equals("SUBMIT"))

could be an issue...try debugging your code & find it out. also would suggest to remove the mentioned if statement.
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
It would be better if you go for MVC architecture. Make a separate class for your persistence logic.

also would suggest to remove the mentioned if statement.
I agree with Anurag


kunal
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Anurag Verma wrote:Guys she replied to a private message

I don't know who "she" is, but both you and her should UseTheForumNotEmail or PMs. A few people may have posted the same solution after those PMs were sent.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to resolved the given error?