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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:42:33+00:00 2026-06-02T23:42:33+00:00

I am getting and error on this line: String selectedValue = this.employeeList.SelectedValue.ToString(); The error

  • 0

I am getting and error on this line:

String selectedValue = this.employeeList.SelectedValue.ToString();

The error I am getting is

NullReferenceException was unhandled.

What does this mean? Can someone help me understand why I am getting this error. Down below is the whole code.

String filePath = this.txtFilePath.Text;
if (!String.IsNullOrEmpty(filePath))
{
    MessageBox.Show("No file path specified");
}

if (this.employeeList.SelectedIndex != -1)
{
    String selectedValue = this.employeeList.SelectedValue.ToString();
    using (StreamWriter writer = new StreamWriter(filePath, true))
    {
        writer.WriteLine(selectedValue);
    }
}
else
{
    MessageBox.Show("No item selected");
}
  • 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-02T23:42:35+00:00Added an answer on June 2, 2026 at 11:42 pm

    That means you are trying to access something which is null (not initialized to any valid value). So add a null check before accessing that.

    I guess in this case, the employeeList.SelectedValue is probably null.

    String selectedValue = string.Empty;
    if(this.employeeList.SelectedValue!=null)
    {
      selectedValue = this.employeeList.SelectedValue.ToString();
    }
    else
    {
      MessageBox.Show("Please select any value");
    }
    

    If you run into any such errors , Always use Visual Studio Breakpoints and Step thru line by line to see what values are coming and where it is breaking. That is the best way to understand what is wrong with the code.

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

Sidebar

Related Questions

I'm getting a compiler error for this line: Collections.sort(terms, new QuerySorter_TFmaxIDF(myInteger)); My customized Comparator
I keep getting an expected identifier error at this line in my code =/
I am getting the object reference error in this line: emp[count].emp_id = int.Parse(parts[0]); in
I am getting this error: Data at the root level is invalid. Line 1,
I am getting an error Incorrect syntax near ',' for this query on line
I am getting this error Thread [TimerDemo(185)id=307040256] (Suspended (exception ClassCastException)) UiApplication.getUiApplication() line: 462 TimerDemoTask$1.run()
I am getting an error in this line of code Session.Linq<Employees>() : An object
Please help me why i'm getting this error. I'm getting Json response converting into
I'm getting this compiler error in netbeans: incompatible types required: String found: java.lang.String I'm
I'm getting this error at this line: Object[] results = (Object[])stmt.getArray(1).getArray(); Not sure what

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.