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?
Manish Pandit - 12 Sep 2006 08:37 GMT
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
FX - 12 Sep 2006 08:41 GMT
ofcourse i have checked tht, i use weblogic workshop, it displays tht
xml field has value inside xmlobject, still there is a problem
> Hi,
>
[quoted text clipped - 3 lines]
> -cheers,
> Manish
Thomas Fritsch - 12 Sep 2006 14:24 GMT
> 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.

Signature
Thomas