NullPointerException creating subscriber with MQ JMS & WAS 4.0

Hi!

I'm getting a NullPointerException when trying to create a subscriber to a topic and have no idea how to deal with this... Any help is very welcome!

java.lang.NullPointerException

at com.ibm.mq.MQQueue.get(MQQueue.java:636)

at com.ibm.mq.MQQueue.get(MQQueue.java:929)

at com.ibm.mq.jms.MQQueueSubscriptionEngine.removeNDSubscriptionEntry(MQQueueSubscriptionEngine.java:1009)

at com.ibm.mq.jms.MQQueueSubscriptionEngine.openSubscription(MQQueueSubscriptionEngine.java:252)

at com.ibm.mq.jms.MQMigrateSubscriptionEngine.openSubscription(MQMigrateSubscriptionEngine.java:261)

at com.ibm.mq.jms.MQTopicSession.createSubscriber(MQTopicSession.java:512)

at com.ibm.mq.jms.MQTopicSession.createSubscriber MQTopicSession.java:336)

at com.newknow.message.NK_RemoteTopicBroadcaster.addListener(NK_RemoteTopicBroadcaster.java:195).

Successful milestones were getting the administered objects from the JNDI namespace:

String icf = "com.ibm.websphere.naming.WsnInitialContextFactory";

String url = "iiop://localhost:900";// url

String tcfLookup = "JmsTopicConnectionFactory"; // Topic connection factory

lookup

// Initialize JNDI properties

Hashtable env = new Hashtable();

env.put(Context.INITIAL_CONTEXT_FACTORY, icf);

env.put(Context.PROVIDER_URL, url);

// get JNDI context

ctx = new InitialContext(env);

// get topic connection factory

factory = (TopicConnectionFactory) ctx.lookup(tcfLookup);

topic = factory.lookupTopic(topicName);

connection = factory.createTopicConnection();

connection.start();

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

The NullPointer exception came at this point:

TopicSubscriber subscriber = session.createSubscriber(topic);

subscriber.setMessageListener(new JMSMessageListener(listener));

Thanks for any idea!

[1971 byte] By [rubencillo] at [2007-9-27 15:47:58]
# 1
I don't think this is necessarily your problem, but you cannot call setMessageListener when running in an Application Server.Also is your broker running?
AlasdairN at 2007-7-5 23:58:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

The problem has been solved with a different aproximation. When defining the topics and connections factories with JMSAdmin application I used:

define t(general)

Changing this to:

define t(general) topic(general)

the exception doesn't occur any more.

Thanks anyway for the suggestion!

rubencillo at 2007-7-5 23:58:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

I see the problem. When you define a topic in JMSAdmin the you have a topic name which is used for binding the object and a topic to publish on. You have to specify both to get a valid object. I'm surprised that JMSAdmin let you define a topic without giving a base topic.

Alasdair

AlasdairN at 2007-7-5 23:58:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...