Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my Static class code:
C#
public static class Maintanance
    {
private static bool haveSet = false;
        public static bool HaveSet
        {
            get
            {
                return haveSet;
            }
            set
            {
                haveSet = value;
            }
        }
}


In calling class:
C#
private void mskPutTime_KeyPress(object sender, KeyPressEventArgs e)
        {
Maintanance.HaveSet = true;
}


I am getting Null Reference exception while I wanna set the value.

What I have tried:

C#
private void mskPutTime_KeyPress(object sender, KeyPressEventArgs e)
        {
Maintanance.HaveSet = true;
}
Posted
Updated 24-Aug-16 7:14am
Comments
[no name] 24-Aug-16 4:06am    
Works fine for me in when calling from a button1_Click(...)
Bernhard Hiller 24-Aug-16 4:11am    
Is there any local variable with the name Maintanance also available? Do a right click on it and select "Go to declaration".
Karthik_Mahalingam 24-Aug-16 4:31am    
post the full code.
phil.o 24-Aug-16 5:10am    
Please post the stack trace also.
Philippe Mori 24-Aug-16 11:46am    
There is nothing wrong in the posted code. If you have a problem, then it must be something else. However, we don't have any useful information to help you.

1 solution

Put a break point in your code on the line
Maintanance.HaveSet = true;

and see if Maintanance is null, if not trace into the set portion of the HaveSet property and see if the variable haveSet is null. The code you posted has both declared static so they shouldn't be null, but if your actual code does not declare them static then they will be null if you don't instantiate them.
 
Share this answer
 

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



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