• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

not getting children in JDom getChildren(String)

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

I have a parent element called "xdp", and a child element called "template". When I get all the children (getChildren) using JDOM and iterate them individually using a loop and use the getName() the answer is "template". But I get a NullPointerException when I go getChildren("template") //According to the documentation the argument is the name. Any ideas why this is happening? do you guys want the code as well?


Thanks.
K.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's really only one reason for that exception: you are trying to call a method on a variable which is null. It has nothing particularly to do with JDOM or XML, it's just plain old programming. So look at the line of code which is throwing the exception -- the stack trace will tell you which line it is -- and find out where you are doing that.

If you still can't figure it out then by all means go ahead and post the relevant code.
 
Karthick Ravi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
:) Yup.. I figured that out.. Thanks Paul.. :thumbup:

If you still can't figure it out then by all means go ahead and post the relevant code.




Anyway, my xml file is





This code




gives me an output of

template
config
localeSet




while the following code throws a NullPointerException






 
Karthick Ravi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Got it.. Damn namespaces.

Changed the code to




and the output looks beautiful.. Thanks Paul.
 
reply
    Bookmark Topic Watch Topic
  • New Topic