Question "An error occurred creating the form" Exception

joshuadeboer

Well-known member
Joined
May 28, 2008
Messages
45
Location
Hillsboro, OR
Programming Experience
1-3
Hi, i was making some changes to my program, and tried to debug it, and it showed this exception:

VB.NET:
"An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object."

I tried restarting the computer, no change.
 
The most likely explanation for that is that something you did in the designer is causing an event that you're handling to be raised and in the event handler you're assuming that a particular object exists but, while the form is still being constructed, it doesn't.

Did you do what the error message told you to do?
See Exception.InnerException for details.
The stack trace of the inner exception will tell you exactly which event handler is the problem.
 
Hi, i figured it out after re-reading the error, it was doing this outside of a sub:

VB.NET:
Dim count As Integer = lstMain.Items.Count

I just changed it so that it set the value when it loads instead.

Thanks
 
Back
Top