some strange error
-
:-D You must be new if you're a stranger to the NullReferenceException! For .NET-related question there's at least two other message boards here that will be more helpful: (Managed) C++/CLI[^] .NET Framework[^]
-
I looked (Managed) C++/CLI and .NET Framework, I used search and found nothing about NullReferenceException! Do you know something about it??
I meant ask your question on one of those message boards - C++/CLI is probably the most appropriate since this isn't a framework question :) The NullReferenceException class' name says it all - it's the exception thrown when you try to dereference a null reference. NullReferenceException Class[^] It should be clear in the debugger which line of your code is using a reference that hasn't been initialized/allocated yet. You may have to view the call stack to find the line in your code (when the exception occurs).
-
I meant ask your question on one of those message boards - C++/CLI is probably the most appropriate since this isn't a framework question :) The NullReferenceException class' name says it all - it's the exception thrown when you try to dereference a null reference. NullReferenceException Class[^] It should be clear in the debugger which line of your code is using a reference that hasn't been initialized/allocated yet. You may have to view the call stack to find the line in your code (when the exception occurs).
debugger shows, taht tihs error comes at this code :
this->b_em.pct->Load("b_em.jpg"); this->b_em.pct->Location = System::Drawing::Point(13, 64); this->b_em.pct->Size = System::Drawing::Size(5, 5); this->b_em.pct->TabIndex = 3; this->b_em.pct->TabStop = false; this->b_em.pct->Visible = false;
so where is probelm ?:) -
debugger shows, taht tihs error comes at this code :
this->b_em.pct->Load("b_em.jpg"); this->b_em.pct->Location = System::Drawing::Point(13, 64); this->b_em.pct->Size = System::Drawing::Size(5, 5); this->b_em.pct->TabIndex = 3; this->b_em.pct->TabStop = false; this->b_em.pct->Visible = false;
so where is probelm ?:)Unfortunately I have never used forms with .NET. There's many helpful people on the .NET boards that have though :) I have no idea what class your "this->b_em.pct" object is so, based on what I see, the only guess I can make is the Load() method call is failing - is the b_em.jpg file in the app exe folder or in the system path? Mark
-
Unfortunately I have never used forms with .NET. There's many helpful people on the .NET boards that have though :) I have no idea what class your "this->b_em.pct" object is so, based on what I see, the only guess I can make is the Load() method call is failing - is the b_em.jpg file in the app exe folder or in the system path? Mark
-
b_em is from structure
ref struct tank { int step_x, step_y; System::Windows::Forms::PictureBox^ pct; };
b_em.jpg is at app exe folder that code is at void InitializeComponent(void) functionDear thesad if you ask on the correct forum(Managed C++/CLI) you can find your answer early
WhiteSky
-
b_em is from structure
ref struct tank { int step_x, step_y; System::Windows::Forms::PictureBox^ pct; };
b_em.jpg is at app exe folder that code is at void InitializeComponent(void) functionOk. I'll take another wild guess - pct is NULL. Maybe try //System::Windows::Forms::PictureBox^ pct = gcnew System::Windows::Forms::PictureBox(); b_em.pct = gcnew System::Windows::Forms::PictureBox(); b_em.pct->Load(... You can save yourself lots of typing by omitting the implied "this->" :)
-
Ok. I'll take another wild guess - pct is NULL. Maybe try //System::Windows::Forms::PictureBox^ pct = gcnew System::Windows::Forms::PictureBox(); b_em.pct = gcnew System::Windows::Forms::PictureBox(); b_em.pct->Load(... You can save yourself lots of typing by omitting the implied "this->" :)
-
I'm learning c++ and using visual studio c++ 2005 express edition. I had written a lot of program's code and try to run, and when it should be started I got an error : An unhandled exception of type 'System.NullReferenceException' occurred in System.Windows.Forms.dll Additional information: Object reference not set to an instance of an object. What must I do, that this error disapear ???
Your first step should be to set a breakpoint with the debugger ( F9 ) and examine your code to see which line blows up, then check to see what variable is null, causing the error. Everything else, is flailing in the dark.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
You are welcome :) Really, consider the C++/CLI board for future CLI-related questions. I get so confused trying to think in .NET when I'm on the C++ board. Cheers! Mark "flailing in the dark" Salsbery ;)