사람들이 전에이 질문을했지만 그 해결책이 저에게 효과적이지 않거나 잘못된 것을하고있는 것으로 보입니다.개체 참조가 개체의 인스턴스로 설정되지 않았습니다. # 100
public class Sprite
{
private Game m_game;
private SpriteBatch m_spriteBatch;
private string m_filename;
private Texture2D m_texture;
public Sprite(Game game, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice)
{
m_game = game;
m_spriteBatch = spriteBatch;
m_texture = new Texture2D(graphicsDevice, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height);
}
public void LoadSprite(string filename)
{
m_texture = m_game.Content.Load<Texture2D>(filename);
}
}
"tree"를 파일 이름으로 전달할 때 오류가 LoadSprite에서 생성됩니다. m_texture가 생성자에서 초기화하려고했기 때문에 null이 아닙니다. Content.Load에 대한 동일한 호출이 기본 루프에서 잘 사용되지만 Sprite 클래스로 이동하려고합니다.
treeTexture = Content.Load<Texture2D>("tree");
주 루프에서 정상적으로 작동하므로 "트리"파일이 있음을 보여줍니다.
내가 뭘 잘못하고 있는지 누가 알 수 있습니까?
m_game 또는 m_game.Content가 null입니까? – Joey
글쎄, 당신의 IDE는 어떤 객체가 NULL인지 쉽게 알려줄 것입니다. 우리는 모르겠다 ... – RvdK
가능한 중복 [.NET의 NullReferenceException 무엇입니까?] (http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net) –