Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to resolved the given error?

 
Mohini Dhanaskar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

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


 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 671
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir, this is the code.



 
Anurag Verma
Ranch Hand
Posts: 168
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please suggest me.
 
Mohini Dhanaskar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now the code showing the following error:


 
Shwetank Arya
Greenhorn
Posts: 4
Eclipse IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried everything ,still not getting why i am getting Null Pointer Exception.
 
Anurag Verma
Ranch Hand
Posts: 168
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am again sending you the code.




and error is :

 
Sumit Patil
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please put a condition for checking if ps is null or not before closing it in the destroy method.
See this
 
Mohini Dhanaskar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 168
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 168
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic