Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

NullPointerExcepion while running jms sample example from jms tutorial  RSS feed

Jitendra Sonawane
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,
I am studying J2EE technology.
I have downloaded J2EESDK , j2ee , jms tutoral and jdk1.3 from
I am working on JMS Api.
In jms tutorial , there are axamples like "SimpleQueueSender" and "SimpleTopicPublisher" in folder "simple".
Now I have done with all the requirements for j2ee server and jdk1.3.
j2ee server runs properly .
I compiled the source code and try to run the above files as per instructions given in tutorial.
"SimpleQueueSender/SimpleTopicPublisher" runs and throws "NullPointerException" with no stack trace available .
Exception occurs when QueueSender tries to send the message to Queue.
I am copying the exception and sample code here for "SimpleQueueSender" .

try {
queueConnection =
queueSession =
queueSender = queueSession.createSender(queue);

System.out.println("Sender 1: " + queueSender) ;
message = queueSession.createTextMessage();
for (int i = 0; i < NUM_MSGS; i++) {
message.setText("This is message " + (i + 1));
System.out.println("Sending message: " +
System.out.println("before sending ... ");
System.out.println("After sending ... ");
Queue name is MyQueue
Java(TM) Message Service 1.0.2 Reference Implementation (build b14)
Sending message: This is message 1
before sending ...
Exception occurred: java.lang.NullPointerException
<<no stack trace available>>

Can anyone Please tell me the reason why there will be NullPointerException ? It happens for both "SimpleQueueSender" and "SimpleTopicPublisher" .. while "SimpleQueueReceiver" and "SimpleTopicSubscriber" works properly .

Jitendra Sonawane
le taylom
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't tested this, but I think your message object is null. I think doing a getText on the message previous to sending it may null it.
Tero Ahonen
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a same kind of problem and the message object is not null. This exception is real mystery
[ February 01, 2002: Message edited by: Tero Ahonen ]
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!