tags:

views:

102

answers:

5
+2  A: 

Are you sure footballLeagueDatabase is getting initialized? I think the constructor where you initialize it is never getting called.

Francisco Soto
+2  A: 

One of the references you are trying to access is null. It is on line 91 in your MainMenu.cs file. Set a breakpoint and have a look with the debugger, what is null?

I would guess that footballLeagueDatabase is null, you need to assign it an instance of type FootballLeagueDatabase.

driis
+4  A: 

You need to learn to read error messages and stack traces.

Look at this bit:

System.NullReferenceException: Object reference not set to an instance of an object. at FoolballLeague.MainMenu.addGameButton_Click(Object sender, EventArgs e) in C:\Users\achini\Desktop\FootballLeague\FootballLeague\MainMenu.cs:line 91

That tells you which line the error is at. It also tells you that it's a NullReferenceException, which means that something is null that shouldn't be.

Set a breakpoint, and step through the relevent code, examining the what happens to the variables, and figure out how it ends up with that null value.

Blorgbeard
+5  A: 

From the exception message I can see that you have a NullReferenceException in addGameButton_Click at line 91. This is line 91:

footballLeagueDatabase.AddGame(game);

So footballLeagueDatabase is null. Let's see the code where you assign to it:

public MainMenu()
{
    InitializeComponent();
    changePanel(1);
}

public MainMenu(FootballLeagueDatabase footballLeagueDatabaseIn)
{
    InitializeComponent();
    footballLeagueDatabase = footballLeagueDatabaseIn;
}

I'd guess either you called the wrong constructor, or you passed a null object into the constructor.

This is the whole code

No, it is not the whole code. You should have some other files in your project. The error is most likely in one of those files (the one that constructs this form).

Mark Byers
+2  A: 

It doesn't look like you initialise the footballLeagueDatabase anywhere

Rowland Shaw