Click here to Skip to main content
15,891,778 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
Object reference not set to an instance of an object. I got this error message and can't find a simple answer on the internet. Thanks for any help that you can give me.
Posted
Comments
[no name] 28-May-12 12:17pm    
Strange, I get 9.630.000 hits on google. And they are all so complicated? Perhaps you should look up the words 'reference type' and the keyword 'new'.

The answer is right there... You have an Object reference which is not set to an instance of an object...
To fix it assign an Object to the reference.
No one here can help you because you have not posted any code, but for a general idea consider the following.
C#
Object obj = null;
obj.ToString(); // Crashes, because you can't call ToString on null!

Object obj = new Object(); // Actually assigning an instance (created with the new keyword) fixes the problem!
obj.ToString();
By the way, the internet is full with this stuff. We get this question at least weekly. Who would have thunk it?[^]
 
Share this answer
 
Comments
[no name] 28-May-12 12:30pm    
Ha! You only got 6.300.000 results. And guess how I deduced that you are from Holland by looking at your link :)
Sander Rossel 28-May-12 12:56pm    
Or perhaps I am trying to fool you all by going to google.nl from my computer in some other country before searching anything!...
Or maybe I am indeed from the Netherlands. Which you also could have deduced from my profile which clearly states I'm from the Netherlands, including flag :)
You are trying to access an attribute of an object that is null.

It is always a good idea to debug your source code. This will easily help you identify and solve such type of errors.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 28-May-12 14:26pm    
Correct, a 5.
--SA
Abhinav S 29-May-12 2:02am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900