The error "Object reference is not set to an instance of the object" appears, which is generally the following reasons:
1. The ViewState object is Null.
2. DateSet is empty.
3. DataReader is empty due to sql statements or Datebase.
4. When declaring a string variable, the variable is applied without assigning a null value.
5. The object is not initialized with new.
6. The Session object is empty.
7. When assigning text values to the control, the value does not exist.
8. When using (), the acquired object does not exist, or the initial value is not assigned when the value is empty
9. When using FindControl, the control does not exist but is not pre-processed.
10. Repeated definition causes an instance error that does not set the object reference to the object
Many times, when running the program, a prompt message like "No object reference is set to an instance of the object" will appear. It is mainly caused by repeated definitions in the code, just delete one of them.
The first: Repeated definition causes an instance error that does not set the object reference to the object
Generally, in C#, the error "not setting the object reference to the instance of the object" is caused by the error. The control name does not correspond to the one in codebehind. For beginners who are learning programming, repeated definitions in the encoding will also cause this kind of problem.
Here is an example:
public string[] c; private void Page_Load(object sender, e){ aaa(); bbb(); } private void aaa(){ string[] c=new string[3]; //c=new string[3]; c[0]="us"; c[1]="west"; c[2]="study"; } private void bbb(){ (c[0]+c[1]+c[2]); }
After running, we will find that the following error will occur:
Exception details: : The object reference is not set to an instance of the object.
Source error:
Line 33: private void bbb()
Line 34: {
Line 35: (c[0]+c[1]+c[2]);
Line 36: }
Route 37:
Many beginners will have questions: I have defined the variable public string[] c, and also instantiated string[] c=new string[3], but why does the error "the object reference is not set to the instance of the object" when calling array c?
The problem lies in string[] c=new string[3]. After the array c has been defined before, the array is defined again in the function aaa(), causing the array defined above to be unable to be instantiated. Just modify string[] c=new string[3] to c=new string[3].
The second type: empty object reference causes an error
1. The control does not exist.
2. Insufficient execution permissions. Add all permissions for ASPNET and EVETRYONE.
1. The ViewState object is Unll.
2. DateSet is empty.
3. DataReader is empty due to sql statements or Datebase.
4. When declaring a string variable, the variable is applied without assigning a null value.
5. The object is not initialized with new.
6. The Session object is empty.
Replenish
C# interim report: The error of not setting the object reference to an instance of the object is generally caused by the object being null. The following are a few simple examples:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //string str1 = ""; //str1 = (','); //No errors are reported //string str2 = null; //str2 = (',');//Error: The object reference is not set to the instance of the object. List<StarInfo> list = null; //if ( > 0 && list != null) //{ // //Logistics and "&&" // //An error: The object reference is not set to the instance of the object. //} //if (list != null && > 0) //{ // //Logistics and "&&" // //There will not be an error. If the conditional statements in if() perform judgments in sequence, when logic and "&&": if the first is flase, the subsequent judgment conditions will not be executed, and so on. // // If the first is true, continue to execute the next judgment condition. // //Note: I have explained it if (list != null && > 0). You must reason according to the conditions you wrote. //} //if ( > 0 || list != null) //{ // //Logic or "||" // //An error: The object reference is not set to the instance of the object. //} //if (list != null || > 0) //{ // //Logic or "||" // //An error: The object reference is not set to the instance of the object. // // If() is judged in sequence, when logical or "||": if the first is flase, the subsequent judgment conditions will continue to be executed, and so on. // // If the first one is true, the judgment condition will not be executed. // //Note: I have explained if(list != null || > 0). You must reason according to the conditions you wrote. //} } }
When the locomotive collection software starts the task running, prompt: The object reference is not set to the instance of the object
Initializing the configuration, please wait...
An error occurred while starting the task: The object reference was not set to the instance of the object. Boolean A0AF549FC79BEB974A2EC34D087596DC6 (Boolean, Boolean, Boolean)
Solution: Copy a copy of the collection rules and paste it to use.
Supplement: You can also exit and save the current rules in the locomotive, and then open them again to check whether the other party’s website makes a source judgment.