Nullpointer exception while getting a XML field

Discussion in 'Java' started by FX, Sep 12, 2006.

  1. FX

    FX Guest

    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?
     
    FX, Sep 12, 2006
    #1
    1. Advertising

  2. 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
     
    Manish Pandit, Sep 12, 2006
    #2
    1. Advertising

  3. FX

    FX Guest

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


    Manish Pandit wrote:
    > 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, Sep 12, 2006
    #3
  4. FX wrote:
    > 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.

    --
    Thomas
     
    Thomas Fritsch, Sep 12, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jens Mueller
    Replies:
    0
    Views:
    624
    Jens Mueller
    Apr 12, 2005
  2. VitaminB
    Replies:
    1
    Views:
    811
    Oliver Wong
    Apr 26, 2006
  3. Replies:
    2
    Views:
    567
  4. =?Utf-8?B?U21pdGE=?=

    Listbox inside a Gridview gives a nullpointer exception

    =?Utf-8?B?U21pdGE=?=, May 30, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    353
    Alexey Smirnov
    May 31, 2007
  5. Chen
    Replies:
    1
    Views:
    910
    Stanimir Stamenkov
    Oct 8, 2008
Loading...

Share This Page