Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6218797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:40:16+00:00 2026-05-24T07:40:16+00:00

Okay, I’ve been trying to fix this for the past week or so, and

  • 0

Okay, I’ve been trying to fix this for the past week or so, and I usually don’t like asking this type of question on here, but I don’t really have a choice at this point.

I’m very new to Java, which I’m sure is the reason for this in the first place.

Well, what I’m trying to do here is to read an XML file with “WBS” (work breakdown structure) nodes and “Activity” nodes, and put them in this data structure for later use. I have a class called WBS, which essentially consists of an ArrayList of children WBS objects, and another ArrayList of Activity objects (another little class). Now here’s the problem: I can get all the “WBS” nodes from the XML file, I can get the “Activity” nodes, but when I try getting both of them in sequence, I get the aforementioned “Null Pointer Exception”. I’m posting all of the code, since, it’s in a number of different files, and quite frankly is not really relevant. However, if you think it would help, I can edit it in.

If either of the Problem lines are edited out, everything works (minus the functionality of the line taken out)

Here’s the problematic code:

   private WBS getWBSStructure(Element initElement){
      WBS structure = new WBS();
      structure.setName(initElement.getElementsByTagName("Name").
            item(0).getChildNodes().item(0).getNodeValue());
      //WBSElement = initElement;
      structure.Children = new ArrayList<WBS>();
      NodeList initAllChildren = initElement.getChildNodes();
      for(int n=0;n<initAllChildren.getLength();n++){
         Node Child = initAllChildren.item(n);
         String childName = Child.getNodeName();
         if(childName=="WBS") {
           structure.Children.add(getWBSStructure((Element)Child));//<--Problem 1
           continue;
         }
         if(childName=="Activity") {
           structure.Activities.add(getActivity((Element)Child));//<--Problem 2
           continue;
         }
      }
      return structure;
   }

   private Activity getActivity(Element initElement){
      Activity act = new Activity();
      act.setName(initElement.getElementsByTagName("Name").
            item(0).getChildNodes().item(0).getNodeValue());
      act.OriginalDuration = Integer.parseInt(initElement.
            getElementsByTagName("PlannedDuration").item(0).
            getChildNodes().item(0).getNodeValue());
      return act;
   }

Comments requstion stack trace. Is this adequate?

java.lang.NullPointerException
at analyzer_main.PriXMLReader.getWBSStructure(PriXMLReader.java:84)
at analyzer_main.PriXMLReader.getWBSStructure(PriXMLReader.java:83)
at analyzer_main.PriXMLReader.getWBSStructure(PriXMLReader.java:60)
at analyzer_main.main_window$1.shellActivated(main_window.java:77)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Decorations.WM_ACTIVATE(Unknown Source)
at org.eclipse.swt.widgets.Shell.WM_ACTIVATE(Unknown Source)
at org.eclipse.swt.widgets.Control.windowProc(Unknown Source)
at org.eclipse.swt.widgets.Canvas.windowProc(Unknown Source)
at org.eclipse.swt.widgets.Decorations.windowProc(Unknown Source)
at org.eclipse.swt.widgets.Shell.windowProc(Unknown Source)
at org.eclipse.swt.widgets.Display.windowProc(Unknown Source)
at org.eclipse.swt.internal.win32.OS.BringWindowToTop(Native Method)
at org.eclipse.swt.widgets.Decorations.bringToTop(Unknown Source)
at org.eclipse.swt.widgets.Shell.open(Unknown Source)
at analyzer_main.main_window.open(main_window.java:60)
at analyzer_main.main_window.main(main_window.java:45)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:40:17+00:00Added an answer on May 24, 2026 at 7:40 am

    This line should give Null pointer exception every time you run this code. No matter if you edited a line before or not.

    if (childName=="Activity") {
        structure.Activities.add(getActivity((Element)Child));
        continue;
    

    You didn’t initialize structure.Activities at all. There should have been something like:

    structure.Activities = new ArrayList<Activity>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I'm trying to pass a pointer to a argument like this. void
Okay this question is very simple: I have a facebook page, and a website.
Okay, this is probably a very basic question; but, I'm just getting back in
Okay, so this is a long long shot but here it goes... When IE
Okay so my question is this. Say I have a simple C++ code: #include
Okay, so I'm trying to make a game that uses this algorithm: http://www.codeproject.com/Articles/15573/2D-Polygon-Collision-Detection But
Okay, so the answer to my question might not be the problem but here's
Okay, so I'm not even sure how to ask this question (much less search
Okay,I've been following this tutorial http://coenraets.org/blog/android-samples/androidtutorial/ Basically it gives me exactly what i need
Okay so here is what I'm trying to accomplish. First of all below table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.