You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by Ceriac <se...@gmail.com> on 2008/12/29 03:26:25 UTC

Please help: Nullpointerexception when using Camel sample code

The sample code I was trying (I keep getting a NullPointerException) is shown
below. I am using Camel 1.5 with ActiveMQ 5.2:

public static void main(String args[]) throws Exception {    	  
	try{  
	  CamelContext context = new DefaultCamelContext();
      // Set up the ActiveMQ JMS Components
      //ConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
      ConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("tcp://localhost:61616");
      context.addComponent("test-jms",
org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
      ProducerTemplate<Exchange> template =
context.createProducerTemplate();
      
      context.start();
      
      for (int i = 0; i < 10; i++) {
          template.sendBody("test-jms:queue:test.queue", "Test Message: " +
i);
    	  }
           
      context.addRoutes(new RouteBuilder() {

          public void configure() {
              from("test-jms:queue:test.queue").to("file://test");
              // set up a listener on the file component
              from("file://test").process(new Processor() {
                  public void process(Exchange e) {
                      System.out.println("Received exchange: " + e.getIn());
                  }
              });
          }
      });     
      
      Thread.sleep(1000);
      context.stop();
	}
	catch(Exception e){
		e.printStackTrace();
	}
	finally{
		System.exit(0);
	}
}

The error I get is as follows:

Dec 28, 2008 8:13:46 PM org.apache.camel.impl.DefaultCamelContext <init>
INFO: JMX enabled. Using InstrumentationLifecycleStrategy.
java.lang.NullPointerException
	at java.lang.String.indexOf(Unknown Source)
	at java.lang.String.indexOf(Unknown Source)
	at org.springframework.jms.JmsException.getMessage(JmsException.java:87)
	at java.lang.Throwable.getLocalizedMessage(Throwable.java:267)
	at java.lang.Throwable.toString(Throwable.java:343)
	at java.lang.Throwable.<init>(Throwable.java:242)
	at java.lang.Exception.<init>(Unknown Source)
	at java.lang.RuntimeException.<init>(Unknown Source)
	at
org.apache.camel.RuntimeCamelException.<init>(RuntimeCamelException.java:39)
	at
org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:724)
	at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:90)
	at
org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:85)
	at
org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:102)
	at
org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:108)

What additional code do I need to add above to solve this problem. Please
help asap.
Thanks,
Ceriac
  
-- 
View this message in context: http://www.nabble.com/Please-help%3A-Nullpointerexception-when-using-Camel-sample-code-tp21198286p21198286.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.