Domanda

Now the problem isnt that i dont know what the error means but i cannot for the life of god figure out what could possibly be the cause of this. I've searched alot looking for answers, but the solution to my anguish eludes me. ive many times tried to overcome my obstacle but failed. Now i look upon you hoping for enlightenment, may you help my brain rest in peace :)

Here comes the problem: Game1 runs and does its thing with my class named Abstakt:

class Abstrakt
{
    public ContentManager content;
    public SpriteBatch spriteBatch;
    public GraphicsDeviceManager graphics;

    MenuComponent menuComponent;
    StartGame startGame;

    public string gameState = "Menu";

    public Abstrakt(SpriteBatch spriteBatch, ContentManager content, GraphicsDeviceManager graphics)
    {
        this.spriteBatch = spriteBatch;
        this.content = content;
        this.graphics = graphics;
    }

    public Abstrakt() { }

    public virtual void Initialize()
    {
        menuComponent = new MenuComponent();
        startGame = new StartGame();

        menuComponent.Initialize();
        startGame.Initialize();
    }

    public virtual void LoadContent()
    {
        menuComponent.LoadContent();
        startGame.LoadContent();
    }
}        






class MenuComponent : Abstrakt
{
    SpriteFont spriteFont;

    public MenuComponent() { }

    public override void LoadContent()
    {
        spriteFont = content.Load<SpriteFont>("GameFont"); <--Here the problem appears
    }
}

Ive removed code that was unimportant so it would be easier to view. th problem is: Object reference not set to an instance of an object.

Thanks for any help and advice.

È stato utile?

Soluzione

I think that you don't initialize the "content" variable.

if you instance a MenuComponent with the default no parameters constructor, content is not assigned.. so it will be equal to null...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top