わかりました、私は本当に奇妙な問題を抱えています。私は今、C#/MonoGame (Linux 上) で簡単なゲームを書いています。をプレイしようとしていSoundEffectます。私が呼び出すときPlay()(メソッドに適切にロードされていてもLoadContent())。NullReferenceExceptionメッセージで を投げていますObject Reference not set to an instance of an object。
コードの構造は次のとおりです
public class MyGame : Game
{
// ..
private SoundEffect _sfx;
public PingGame ()
{
// ...
}
protected override void Initialize ()
{
// ...
}
protected override void LoadContent ()
{
// ...
// No errors here on loading it
_sfx = Content.Load<SoundEffect>("noise.wav");
}
protected override void Update (GameTime gameTime)
{
// ...
if (playSound)
{
// This is where the error is thrown
_sfx.Play();
}
// ...
}
protected override void Draw (GameTime gameTime)
{
// ..
}
}