UNhandled Exception of Type System.NullReferenceException
-
In my project two forms(form1 and form2) when from form1 i try to Access any object of from2 then it give me error that object reference not set to an instance of object, me using following way in form1 i create the obg of from2 as from2 f=new fomr2(); Bitmap b=(Bitmap)f.pictureBox1.Image; if(b.GetPixel(100,100)==-1) {//code} it give the abovemention error in if statement when i try to accec the pixels of that object. What should i do?????????
-
In my project two forms(form1 and form2) when from form1 i try to Access any object of from2 then it give me error that object reference not set to an instance of object, me using following way in form1 i create the obg of from2 as from2 f=new fomr2(); Bitmap b=(Bitmap)f.pictureBox1.Image; if(b.GetPixel(100,100)==-1) {//code} it give the abovemention error in if statement when i try to accec the pixels of that object. What should i do?????????
Just by instantiating the form does not necessarily mean that the picture box will have anything in it. Thefore the error is correct. Where does the picture box get its image? Once you have the answer to that then you know what else you need to instantiate in order to get your code to work.
*** Developer Day 4 in Reading, England on 2nd December 2006 - Registration Now Open *** Upcoming Scottish Developers events: * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
Just by instantiating the form does not necessarily mean that the picture box will have anything in it. Thefore the error is correct. Where does the picture box get its image? Once you have the answer to that then you know what else you need to instantiate in order to get your code to work.
*** Developer Day 4 in Reading, England on 2nd December 2006 - Registration Now Open *** Upcoming Scottish Developers events: * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
PictureBox take its image from file and i m sure that pictureBox has its image,this is not empty pictureBox but still it give thte above mentioned error
signimage wrote:
PictureBox take its image from file and i m sure that pictureBox has its image,this is not empty pictureBox but still it give thte above mentioned error
Obviously, it is an empty picture box at the time you are running your code otherwise you would not be getting the error. Since you don't seem to be doing anything else with the form (at least from the code you provided) then I would suggest that you probably don't need the form anyway. Perhaps you just need to instantiate a Bitmap with the relevant file and use that.
*** Developer Day 4 in Reading, England on 2nd December 2006 - Registration Now Open *** Upcoming Scottish Developers events: * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
Just by instantiating the form does not necessarily mean that the picture box will have anything in it. Thefore the error is correct. Where does the picture box get its image? Once you have the answer to that then you know what else you need to instantiate in order to get your code to work.
*** Developer Day 4 in Reading, England on 2nd December 2006 - Registration Now Open *** Upcoming Scottish Developers events: * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
i face the same problem when ever i try to acces any object of form from any other calss (within same project) how to acces the form object (like picture) from any other calss i use the form obj to acces the formobjfrom other class but it give reference inmstance error
-
i face the same problem when ever i try to acces any object of form from any other calss (within same project) how to acces the form object (like picture) from any other calss i use the form obj to acces the formobjfrom other class but it give reference inmstance error
That is because it is obviously not instantiated properly. A form is a class designed to store stuff that is displayed on the screen (within that form). If you are not going to display it on the screen then your design is screwed up and you should reconsider what you are doing.
*** Developer Day 4 in Reading, England on 2nd December 2006 - Registration Now Open *** Upcoming Scottish Developers events: * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
signimage wrote:
PictureBox take its image from file and i m sure that pictureBox has its image,this is not empty pictureBox but still it give thte above mentioned error
Obviously, it is an empty picture box at the time you are running your code otherwise you would not be getting the error. Since you don't seem to be doing anything else with the form (at least from the code you provided) then I would suggest that you probably don't need the form anyway. Perhaps you just need to instantiate a Bitmap with the relevant file and use that.
*** Developer Day 4 in Reading, England on 2nd December 2006 - Registration Now Open *** Upcoming Scottish Developers events: * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
is there any way to access the from object from another class,usually i create the obj of form then using that obj we access the obj from form then why it give me the null reference erroe, and im sur that obj has obj referenc but it cannot send this reference to other class,(why)
-
That is because it is obviously not instantiated properly. A form is a class designed to store stuff that is displayed on the screen (within that form). If you are not going to display it on the screen then your design is screwed up and you should reconsider what you are doing.
*** Developer Day 4 in Reading, England on 2nd December 2006 - Registration Now Open *** Upcoming Scottish Developers events: * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
Colin Angus Mackay wrote:
That is because it is obviously not instantiated properly
how to instantiat object properly?
SomeClass instance = new SomeClass();
or variations on that theme. See the class documentation in MSDN for details. Some objects use static Create methods instead.
*** Developer Day 4 in Reading, England on 2nd December 2006 - Registration Now Open *** Upcoming Scottish Developers events: * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog