Hi,

I'm new to this jms. i have written a program to pass java objects to the JMS but i'm getting error as Exception in thread "main" java.lang.NullPointerException, When i run producer.java programme. So please let me know whats wrong in my program.

Here is the code..

******************************************
TestPro.java
******************************************

package com.test.msg;

import java.io.Serializable;

public class TestPro implements Serializable
{
private String msg;

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}
}

**************************************
producer.java
***************************************

package com.test.producer;

import javax.jms.*;

import org.apache.activemq.ActiveMQConnectionFactory;

import com.test.msg.TestPro;

public class Producer {

private static String url = "tcp://localhost:5003";
public static Connection connection;
private static String TEST_QUEUE = "TEST";

public static MessageProducer producer;
public Session session;
String TEST_MESSAGE;

public static void main(String[] args) throws JMSException
{
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
connection = connectionFactory.createConnection();
connection.start();

Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

Destination destination = session.createQueue(TEST_QUEUE);
producer = session.createProducer(destination);
//TextMessage message = session.createTextMessage("Hello Rohith WelCome To ActiveMQ");
Producer produce = new Producer();
TestPro testPro = new TestPro();
testPro.setMsg("Hello......");
produce.sendData(testPro);

}

public void sendData(TestPro message) throws JMSException
{
ObjectMessage objectMessage = session.createObjectMessage();
objectMessage.setObject(message);
objectMessage.setJMSCorrelationID("ID:"+ TEST_MESSAGE);
producer.send(objectMessage);
System.out.println("Send Message" +(String)objectMessage.getObject());
connection.close();
}
}
*************************************************
cunsumer.java
***********************************************

package com.test.consumer;

import javax.jms.*;

import org.apache.activemq.ActiveMQConnectionFactory;

public class Consumer {

private static String url = "tcp://localhost:5003";
public static Connection connection;
private static String TEST_QUEUE = "TEST_QUEUE";

public static MessageConsumer consumer;

public static void main(String arg[]) throws JMSException
{
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
Connection connection = connectionFactory.createConnection();
connection.start();

Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(TEST_QUEUE);
consumer = session.createConsumer(destination);
/*Message message = consumer.receive();

if(message instanceof TextMessage)
{
TextMessage textMessage = (TextMessage)message;
System.out.println("Received Message " + textMessage.getText());
}*/
Consumer consume = new Consumer();
consume.onMessage(message)
}

public void onMessage(Message message) throws JMSException
{
ObjectMessage objectMessage = (ObjectMessage) message;
System.out.println("Receive Message: " + (String)objectMessage.getObject());
connection.close();
}

}
************************************************** ***
In consuner.java how to make main method to access onMessage menthod... Please help........