Nullpointer exception while getting a XML field

F

FX

i am trying to get a field <tag> from an xml object.
when i do this i get Null pointer exception
String a=xmlobj.getEdi().getdocnum();
this gives NPE.... although sml format is exactly the same as the
method of getting it
also it has value(not empty)... wat cud be possible reasons?
 
M

Manish Pandit

Hi,

Do check if your xmlObject is null before invoking a method on it. What
parser you are using, and is this an XML Bean?

-cheers,
Manish
 
F

FX

ofcourse i have checked tht, i use weblogic workshop, it displays tht
xml field has value inside xmlobject, still there is a problem
 
T

Thomas Fritsch

FX said:
i am trying to get a field <tag> from an xml object.
when i do this i get Null pointer exception
String a=xmlobj.getEdi().getdocnum();
this gives NPE.... although sml format is exactly the same as the
method of getting it
also it has value(not empty)... wat cud be possible reasons?
2 possible reasons:
(1) xmlobj is null => NPE when trying to call getEdi()
(2) getEdi() returns null => NPE when trying to call getdocnum()

Unfortunately these 2 possibilities are not distinguishable in your
exception stack trace, because they occur at the same line number.

Therefore I would split the single line into 2 lines:
Edi edi = xmlobj.getEdi();
String a = edi.getdocnum();
and see which line number is now reported in the NPE's exception stack
trace.

Then think why that object (either xmlobj, or edi) was null, and how you
can avoid it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top