How to iterate xml in java



I would like to get all values from xml until its got end. But I am facing null pointer exception at end. Please expalin me how to get each values from xml and assign it to variables. xml = response.get().asXml();



int i=0;
while(xml.hasChildNodes())
{

NodeList node = xml.getChildNodes().item(0).getChildNodes();
message = node.item(i).getTextContent();
//message = node.item(i).getTextContent();

System.out.println(message);
i++;
}


Log message



'13-ARTENGO-P1046'
'1'
'1614113'
'2014-10-16 12:53:33.663165'
'13-ARTENGO-P1046'
'1'
'1799748'
'2014-10-16 12:53:33.663165'
'13-ARTENGO-P1046'
'1'
'1799597'
'2014-10-16 12:53:33.663165'
'13-ARTENGO-P1046'
'1'
'8225610'
'2014-10-16 12:53:33.663165'
[error] ShipmentSearch - Error occured due to: null
java.lang.NullPointerException
at webservices.GetAllBoxDetails.browseAll(GetAllBoxDetails.java:55)
at controllers.Application.searchshipment(Application.java:58)
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$2$$anonfun$apply$2.apply(routes_routing.scala:77)
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$2$$anonfun$apply$2.apply(routes_routing.scala:77)
at play.core.Router$HandlerInvoker$$anon$6$$anon$2.invocation(Router.scala:141)
at play.core.Router$Routes$$anon$1.invocation(Router.scala:322)
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:31)
at play.db.jpa.TransactionalAction$1.apply(TransactionalAction.java:19)
at play.db.jpa.TransactionalAction$1.apply(TransactionalAction.java:17)
at play.db.jpa.JPA.withTransaction(JPA.java:101)
at play.db.jpa.TransactionalAction.call(TransactionalAction.java:14)
at play.core.j.JavaAction$$anon$2.apply(JavaAction.scala:74)
at play.core.j.JavaAction$$anon$2.apply(JavaAction.scala:73)
at play.libs.F$Promise$PromiseActor.onReceive(F.java:420)
at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:159)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425)
at akka.actor.ActorCell.invoke(ActorCell.scala:386)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:230)
at akka.dispatch.Mailbox.run(Mailbox.scala:212)


Please anyone help me to solve this issue.

No comments:

Post a Comment