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 6739597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:30:27+00:00 2026-05-26T11:30:27+00:00

I keep having null pointer exception when i add to header.headerItems.Add(d2); in which my

  • 0

I keep having null pointer exception when i add to header.headerItems.Add(d2); in which my headerItems is an observable collection of type Data

Anyone can tell me why is this ?

 private void addData(Header header)
 {
        Data d2 = new Data("pol");
        header.headerItems.Add(d2);
 }

my Method which call this method is just as below. In which header is part of a Packet class.

addData(packet.header);

My header class

public class Header
    {
    private ObservableCollection<Data> headerCollection;
    private String sheadervalue;
    public Header(String headervalue)
    {
        sheadervalue = headervalue;
    }

    public ObservableCollection<Data> headerItems
    { get { return headerCollection; } }

    public string headervalue
    {
        get { return sheadervalue; }
        set { sheadervalue = headervalue; }
    }
}

My data class

  public class Data
{
    private String sDatavalue;

    public Data(String datavalue)
    {
        this.sDatavalue = datavalue;

    }

    public string datavalue
    {
        get { return sDatavalue; }
        set { sDatavalue = datavalue; }
    }

}
  • 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-26T11:30:28+00:00Added an answer on May 26, 2026 at 11:30 am

    problem is you accessing field of null object (header). do as below

    private void addData(Header header)
     {
        if(null == header)
        {
           // if header null what you can do... e.g log header is null 
           return; 
        }
        if(null == header.headerItems)
        {
            header.headerItems = ....; // create new header item collection 
        }
    
        Data d2 = new Data("pol");
        header.headerItems.Add(d2);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to mock Server.HtmlEncode(), but I keep having a null reference exception. I'm
I keep hearing from associates about grid computing which, from what I can gather,
I keep getting Clang errors on the following type of code and I can't
I keep having complaints that users are logged in as each other. They can
I keep having problems with Winforms data-binding, more specifically, whenever I specify a period-separated
I keep having an error when running my web application. The error does not
I'm writing a C program but I keep having problems with my array of
The problem that I am having has to do with the need to keep
I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
I keep running across this loading image http://georgia.ubuntuforums.com/images/misc/lightbox_progress.gif which seems to have entered into

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.