My program stops working with this warning
An unhandled exception of type ‘System.NullReferenceException’ occurred in WindowsFormsApplication10.exe
Additional information: Object reference not set to an instance of an
object.
Here is the code where it stops:
string stripStatusL = "some text: " + keepValues[lastTaken].ToString();
toolStripStatusLabel1.Text = stripStatusL;
It’s just a StatusStrip with Label in. I’m trying to change the text of that Label. Usually it works for Label without StatusStrip. What is my mistake?
Visual Studio 2010
C#
My best guess would be that
keepValuesisnullor thatlastTakenindex/key (your code doesn’t say whether it’s a list or dictionary) does not exist in the collection. The usual reason for that is that the forms designer might not be able to pass in external data on initialization. Forms have aDesignModeproperty which is true if the form is run in the designer which you can use to provide some mock data if required.