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

  • Home
  • SEARCH
  • 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 6853151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:28:38+00:00 2026-05-27T01:28:38+00:00

I have a Setting.cs file containing the info [Serializable] public class Setting { public

  • 0

I have a Setting.cs file containing the info

[Serializable]
public class Setting
{
    public Setting()     {}

    public String defaultAlertTone = Path.GetDirectoryName(Application.ExecutablePath) + "\\Sounds\\applause-2.wav";        
}

and my settingsForm retrieving the info through this code

Setting settingObject;
public SoundPlayer player;

public settingsForm(backgroundForm backgroundFormObject)
{
    InitializeComponent();
    this.backgroundFormObject = backgroundFormObject;
    settingObject = backgroundFormObject.getSetting();
}

private void InitializeSound()
{
    // Create an instance of the SoundPlayer class.
    player = new SoundPlayer();
    player.SoundLocation = settingObject.defaultAlertTone;

    // Listen for the LoadCompleted event.
    player.LoadCompleted += new AsyncCompletedEventHandler(player_LoadCompleted);

    // Listen for the SoundLocationChanged event.
    player.SoundLocationChanged += new EventHandler(player_LocationChanged);
}

Why is it that every time I run the app, there would be a null reference exception on the

player.SoundLocation = settingObject.defaultAlertTone;

the backgroundFormObject.getSetting(); is just a method to retrieve the setting object. the code for it are as follows

Setting settingObj = new Setting();

public Setting getSetting()
    {
        return settingObj;
    }
  • 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-27T01:28:39+00:00Added an answer on May 27, 2026 at 1:28 am

    The reasons could be

    1. InitializeSound() is somehow running before settingsForm (not likely, but this would make the settingObject not initialized and refer to null).
    2. If this is the complete code for Setting class, i don’t see how calling new Setting() anywhere would make a difference. So use Setting settingObject = new Setting(); when you first define this property in the settingsForm class.
    3. It is not the settingObject which is null.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .settings file (containing both User and Application settings) that I would
If I have the following setting in my app.config file. It is a setting
It is typical to have something like this in your cshrc file for setting
I have a settings file in my Winforms application called Settings.settings with a partial
I have successfully developed and deployed a ClickOnce application which registers an associated file
I am setting up a hash reference containing file handles. The fourth column of
I have an array containing a list of file paths that I want to
I have a data structure representing a CSV file containing thousands of config settings.
I have written a program which reads a file containing multidimensional data (most commonly
(its a long story) but I have a large complex project file containing 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.