- Joined
- Dec 11, 2014
- Messages
- 2,004
I'm new to these stuff, trying to create a small app for my school, getting an error at the time of entry.
The error:
"An unhandled exception of type 'System.NullReferenceException' occurred in ThisApplication.exe
Additional information: Object reference not set to an instance of an object."
I seriously don't understand why StdName has a null reference. i is 1. Globals is a class. StdName is a string array and the value is correct. What's the problem?? Even worse, Globals.Max does not throw an error.
Any ideas?
QUICK EDIT: Removing the array makes it work. With the array it does not work, it throws the null error. Putting Globals.StdName[1] = "s"; also doesn't work; which means the whole problem is the array. Using struct/class instances instead of arrays makes it harder, don't say that please
Code:
namespace meh
public class Globals
{
public static string[] StdName;
public static int Max;
}
public partial class MainForm : Form // ye I'm using VS forms which means this is the entry point instead of Main()
{
public MainForm()
{
InitializeComponent();
new Globals();
int i = 1;
Globals.Max = 28;
Globals.StdName[i] = "s"; //error here
}
}
The error:
"An unhandled exception of type 'System.NullReferenceException' occurred in ThisApplication.exe
Additional information: Object reference not set to an instance of an object."
I seriously don't understand why StdName has a null reference. i is 1. Globals is a class. StdName is a string array and the value is correct. What's the problem?? Even worse, Globals.Max does not throw an error.
Any ideas?
QUICK EDIT: Removing the array makes it work. With the array it does not work, it throws the null error. Putting Globals.StdName[1] = "s"; also doesn't work; which means the whole problem is the array. Using struct/class instances instead of arrays makes it harder, don't say that please