Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

Nullpointer exception while getting a XML field

Thread view: 
FX - 12 Sep 2006 08:31 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?
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.