Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with NullPointerException Error

 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am Having a problem with Null Pointer Exception. I have this method which i know can return a Null result

if (message.getJMSCorrelationID().equals(null)){
message.setJMSCorrelationID("1");
}

And i am doing the test and i have taking care of the Null problem by setting the JMSCorrelationID to 1, but its still giving me an error, Jumping to the Catch Block Instead
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Abiodun Oyesiji:
Hello,
I am Having a problem with Null Pointer Exception. I have this method which i know can return a Null result

if (message.getJMSCorrelationID().equals(null)){
message.setJMSCorrelationID("1");
}

And i am doing the test and i have taking care of the Null problem by setting the JMSCorrelationID to 1, but its still giving me an error, Jumping to the Catch Block Instead


Try
 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried That Still not working
 
Henry Wong
author
Marshal
Pie
Posts: 21115
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't guess on what could be causing the NPE. The stack trace actually does a great job at giving you the file and line number where the exception occured.

You should confirm that it is actually where you think it is first.

Henry
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joanne Neal:


Alternatively you can try this one



But you must show the stack trace, this can be possible that the original source of nullPointerException can be unawered by you completely.

Pls share the stack trace alongwith the code so that we can identify the nullpointer exception.

Hope this helps you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic