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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:58:37+00:00 2026-06-08T13:58:37+00:00

I have been up half the night and still trying to get this null

  • 0

I have been up half the night and still trying to get this null exception figured out. I have read a few of texts about this issue but none has helped me in any way, to me what the problem is as it should work :/ It just crashes at this piece of code:

Private void UpdateGUI()
{
    string selectedItem  = cmbDisplayOptions.Items[cmbDisplayOptions.SelectedIndex].ToString();
    rdbtReserv.Checked = true;            
    lstReservations.Items.Clear();           
    lstReservations.Items.AddRange(m_seatMngr.GetSeatInfoStrings(selectedItem));
}

lstReservations.Items.AddRange(m_seatMngr.GetSeatInfoStrings(selectedItem)); Gives me the ArgumentNullExeption, but to me it should not do that.

the addrange sends string selectedItem to another class:

    public string[] GetSeatInfoStrings(string selectedItem)
    {
        int count = GetNumOfSeats(selectedItem);

        if (count <= 0)
        {
            return null;
        }

        string[] strSeatInfoStrings = new string[count];

        for (int index = 0; index <= m_totNumOfSeats - 1; index++)
        {
            strSeatInfoStrings[index] = GetSeatInfoAt(index); 
        }

        return strSeatInfoStrings;

    }

This int count = GetNumOfSeats(selectedItem); goes to here and returns with an int:

    private int GetNumOfSeats(string selectedItem)
    {
        if (selectedItem == "ReservedSeats")
        {
            return GetNumReserved();
        }
        if (selectedItem == "VacantSeats")
        {
            return GetNumVacant();
        }
        else
        {
            return m_totNumOfSeats;
        }
    }

I have checked the arrayed have the correct number of spaces(60) and that selectedItem has a string(Allseats to start with so it should return m_totnumOfSeats which is an int of 60) But then in the private int GetNumOfSeats something goes wrong and it returns null and…well why?

I can’t see the problem.. maybe gone blind by trying to find the issue. Always got outstanding help here and I have learned tons!! So maybe someone can point out all the issues there is in my code.

Thanks a million in advance for any and all advice!

//Regards

  • 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-06-08T13:58:39+00:00Added an answer on June 8, 2026 at 1:58 pm

    Check if your variables are actually initialized and returns correct values.

    There are logical errors in the GetSeatInfoStrings methods and the GetNumofSeats method.

    Lucky for you the GetNumOfSeats method will always return 60 for you because of the wrong way you compare strings. It’s not the right way, so use the Equals method for comparison like

     if (selectedItem.Equals("ReservedSeats"))
    

    With that you will get a proper output form GetNumOfSeats(string) method.

    The next thing is to fix your looping in the GetSeatInfoStrings method so as to not get an array index out of bounds exception like this.

        string[] strSeatInfoStrings = new string[count];
    
        for (int index = 0; index <= count; index++)
        {
            strSeatInfoStrings[index] = GetSeatInfoAt(index); 
        }
    
        return strSeatInfoStrings;
    

    Also fix the part where your logic returns a null in the GetSeatInfoStrings method. it should return an empty string array according to your logic as

        return new string[0];
    

    That should probably get your methods working. You need to be very careful of what you code before you debug it 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to get this seemingly simple problem fixed for about half
I have been trying for half a day to loop this countdown function. I
I have been trying to get this layout correct and having trouble. Here is
I have been trying for about a day and a half to get the
I have been around the world twice and a half trying to fix a
I have spent hours trying to work this out, and spent a long time
I have been trying to work out how the text in the nav and
I have been wrestling with SvcUtil all day, trying to get it to generate
I have been searching the internet for days trying to solve this problem. I
I have been trying to figure out how to display a advertisement on a

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.