hit another problem during my C# practise. This is short explanation of it: In Program.cs I have the following code:
namespace testApp
{
public class AppSettings
{
public static int appState { get; set; }
public static bool[] stepsCompleted { get; set; }
}
public void Settings
{
appState = 0;
bool[] stepsCompleted = new bool[]{false, false, false, false, false};
}
}
static class MyApp
{
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new gameScreen());
AppSettings appSettings = new AppSettings();
}
}
And this is in the Form1.Designer.cs:
namespace testApp
{
private void InitializeComponent() {..}
private void detectPressedKey(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13) // Enter = code 13
{
if (AppSettings.appState == 0)
{
if (AppSettings.stepsCompleted[1] == false) // << here we have an EXCEPTION!!!
{
this.playSound("warn");
}
}
}
}
}
The problem is in the commented if where I get NullReferenceException: Object reference not set to an instance of an object. Searched a bit through the net but cannot find where is the problem. AppSettings.stepsCompleted should exist like AppSettings.appState
AppSettings.stepsCompleted, so it will be null. It does exist, but it doesn't have a value, so attempting to access its elements will throw a NRE.