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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:49:58+00:00 2026-05-27T23:49:58+00:00

I have a basic sound manager class that’s derived from an online example: http://www.xnawiki.com/index.php?title=Basic_Sound_Manager_For_XNA_GS_3.0

  • 0

I have a basic sound manager class that’s derived from an online example: http://www.xnawiki.com/index.php?title=Basic_Sound_Manager_For_XNA_GS_3.0

The problem is that whenever I call the LoadSound(string assetName, string assetPath) method, I get a NullReferenceException. I’m guessing this means the content manager couldn’t find the reference specified and is returning null.
It doesn’t make sense to me though, as there are definitely sounds in the content folder I’m referencing. It worked before I moved sound management to a separate class.

Here’s the relevant code snippet for my SoundManager class:

public static class SoundManager
{
    // Class variables
    static Dictionary<string, SoundEffect> sounds = new Dictionary<string,
                                                             SoundEffect>();
    static Song currentSong;
    static ContentManager content;
    static float soundVolume = 1f;

    // Initialize: Load the game's content manager.
    public static void Initialize(Game game)
    {
        content = game.Content;
    }

    public static void LoadSound(string assetName)
    {
        LoadSound(assetName, assetName);
    }

    // Load a sound from a passed name into the dictionary
    public static void LoadSound(string assetName, string assetPath)
    {
        sounds.Add(assetName, content.Load<SoundEffect>(assetPath));
    }
}

The exception occurs in the line

sounds.Add(assetName, content.Load<SoundEffect>(assetPath));

In Game1’s Initialize() method, I’m calling:

SoundManager.Initialize(this);

In Game1’s LoadContent() method, I’m calling the following:

SoundManager.LoadSound("collision", "Sounds\\collision");

The Content.RootDirectory is “Content”, and a sound exists at content/sounds/ding.wav (asset name collision). I seriously can’t see any problems here. If there are any weird scope problems anyone can see, please help, I have an impending deadline.

  • 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-27T23:49:58+00:00Added an answer on May 27, 2026 at 11:49 pm

    If the NRE is in your code, then it’s got to be that content is null: i.e., Initialize is not being called before LoadSound. Use a breakpoint or some quick debugging to check this is the case.

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

Sidebar

Related Questions

I have a basic class that derived subclasses inherit from, it carries the basic
I am using a very basic java sound class to stream audio from Bing
I have basic hello word example of Prime Faces. I have created dynamic web
I have a basic has_many :through relationship that is bi-directional: calendars have many calendar_calendar_events
I have a basic PHP question, take the code below for example, let's say
I have some basic questions around understanding fundamentals of Performance testing. I know that
I'm fairly new to directx so this may sound really basic. I have started
I have a basic data model that I want to implement in MySQL. I
I understand this question may sound very basic but I have been trying to
I have a question about the basic wav file data chunk. I know that

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.