System.NullReferenceException
I have managed to get my code to compile, but when I run it, it crashes with the following error:
System.NullReferenceException: Object reference not set to an instance of an object
It occurs when the program reaches this/these statements:
Hex *Map = new Hex[max_x_coordinate*max_y_coordinate*max_z_coordinate];
Hex *pWorld = Map;
I tried putting
Hex *Map = 0; above and then using Map = new Hex[..], but it still gave me the same error.
I took out this part of the code and placed it in a new file just by itself (along with the needed class). It once again compiled fine, but gave the same error.
I talked with a friend about the error, but he had no clue what I could be doing wrong.
Anyone have any ideas?
Thanks,
Ken
Put a breakpoint above the location the exception happens and step through the code. Look for null-pointers. To tell you more I would need to see more of the code.
I can get the code to compile, but upon execution I receive that error. Here it is below:
Universe PBEM Wargame Moderator Software
Version .1 Alpha
1) Create Generic Map
2) Edit Map
1
You have selected to generate a generic map.
Therefore, we need some basic information to do so.
Please enter the maximum number for the x axis.
20
Please enter the maximum number for the y axis.
20
Please enter the maximum number for the z axis.
When considering how many planes (i.e. z = # of planes)
to have, take into consideration the fact that x * y * z * size of hex class
is limited by the amount of memory of your computer.
1
Next, we need the pathway for the generic map to be stored.
Please enter in a format like C:\Universe\Maps\Abaddon\Abaddon.txt.
Please also note that the pathway is limited to 255 characters total and must NO
T contain numbers.
C:\Abaddon.txt
Next, pleease enter the name of the map.
Abaddon
Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
at Hex.Set_x_coordinate(Hex* , UInt16 x) in c:\documents and settings\adminis
trator\my documents\visual studio projects\b\b.cpp:line 25
at create_generic_map() in c:\documents and settings\administrator\my documen
ts\visual studio projects\b\b.cpp:line 452
at main() in c:\documents and settings\administrator\my documents\visual stud
io projects\b\b.cpp:line 590
Since I don''t know how to create a box to put code in, I''ve uploaded the source to the following address:
http://members.aol.com/oglahai/universe_pbem_software.cpp
I''m not very good at programming, so please forgive the horrid code.
Thanks,
Ken
Universe PBEM Wargame Moderator Software
Version .1 Alpha
1) Create Generic Map
2) Edit Map
1
You have selected to generate a generic map.
Therefore, we need some basic information to do so.
Please enter the maximum number for the x axis.
20
Please enter the maximum number for the y axis.
20
Please enter the maximum number for the z axis.
When considering how many planes (i.e. z = # of planes)
to have, take into consideration the fact that x * y * z * size of hex class
is limited by the amount of memory of your computer.
1
Next, we need the pathway for the generic map to be stored.
Please enter in a format like C:\Universe\Maps\Abaddon\Abaddon.txt.
Please also note that the pathway is limited to 255 characters total and must NO
T contain numbers.
C:\Abaddon.txt
Next, pleease enter the name of the map.
Abaddon
Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
at Hex.Set_x_coordinate(Hex* , UInt16 x) in c:\documents and settings\adminis
trator\my documents\visual studio projects\b\b.cpp:line 25
at create_generic_map() in c:\documents and settings\administrator\my documen
ts\visual studio projects\b\b.cpp:line 452
at main() in c:\documents and settings\administrator\my documents\visual stud
io projects\b\b.cpp:line 590
Since I don''t know how to create a box to put code in, I''ve uploaded the source to the following address:
http://members.aol.com/oglahai/universe_pbem_software.cpp
I''m not very good at programming, so please forgive the horrid code.
Thanks,
Ken
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement