Jagged Arrays in Managed code
Im working on a Windows Forms project and I cant seem to figure this out. The code compiles without error or warnings however during runtime I get the following error:
An unhandled exception of type 'System.NullReferenceException' occurred
Additional information: Object reference not set to an instance of an object.
I am including a very shortened example of my coding.
In a class header file I have the following:
public ref class Profile
{
public:
Profile(void)
{
Init();
}
array<String^>^ Keys;
Init()
{
Keys = gcnew array<String^>(10);
}
};
In the Main header file I have the following(some stuff such as #include left out for conciseness):
public ref class Main
}
public:
Main(void)
{
Init();
}
Profile^ Profiles;
Init()
{
array<Profile^>^ Profiles = gcnew array<Profile^>(10);
Profiles[0]->Keys[0] = "TEST"; //This line generates the error during runtime.
}
If the object Keys is defined as String^ rather than array<String^>^ I can access that member with Profiles[0]->Keys; However when it is defined as an array I cant access it. This is an array defined in the class that I am making an array of. Ive tried to figure out what Im doing wrong for over 8 hours with no luck.
Last edited by sweinhart2006; May 23rd, 2009 at 02:30 AM..
|