I must be missing something here, but I've got an instance of my submission object called up, in scope, and when I try to use it in another line, I throw this error about not setting the reference to an instance. What gives?
我必须在这里遗漏一些东西,但是我已经在范围内调用了我的提交对象的实例,当我尝试在另一行中使用它时,我抛出了关于不设置对实例的引用的错误。是什么赋予了?
protected void Page_Load(object sender, EventArgs e)
{
string x = Request.QueryString["SubmissionId"];
SubmissionService ss = new SubmissionService();
Submission sub = ss.getSubmissionByID(x);
if (sub.Status1.Equals(0))
{
PanelComment.Visible = false;
}
else
4 个解决方案
#1
1
It's possible that the Status1 property on your submission object 'sub' is null...
提交对象'sub'上的Status1属性可能为null ...
#2
3
These could be null:
这些可以为null:
ss
sub
sub.Status1
x
Put a breakpoint, and debug...
放一个断点,然后调试......
#3
1
Given the code that you supplied, there can be three causes:
鉴于您提供的代码,可能有三个原因:
- the "Status1" property is null, this would generate a NullReferenceException.
- PanelComment is null
- sub is null
“Status1”属性为null,这将生成NullReferenceException。
PanelComment为null
sub为null
#4
0
Given the code, the following properties could be null:
给定代码,以下属性可以为null:
- Submission sub (If there is no submission with the ID = x)
- sub.Status1
- List item
提交子(如果没有提交ID = x)
PanelComment
Just change your code by the following:
只需通过以下方式更改您的代码:
Submission sub = String.IsNullOrEmpty(x) ? null : ss.getSubmissionByID(x);
if (sub!= null && sub.Status1 == 0){
...
It should fix most of the null references.
它应该修复大多数空引用。
#1
1
It's possible that the Status1 property on your submission object 'sub' is null...
提交对象'sub'上的Status1属性可能为null ...
#2
3
These could be null:
这些可以为null:
ss
sub
sub.Status1
x
Put a breakpoint, and debug...
放一个断点,然后调试......
#3
1
Given the code that you supplied, there can be three causes:
鉴于您提供的代码,可能有三个原因:
- the "Status1" property is null, this would generate a NullReferenceException.
- PanelComment is null
- sub is null
“Status1”属性为null,这将生成NullReferenceException。
PanelComment为null
sub为null
#4
0
Given the code, the following properties could be null:
给定代码,以下属性可以为null:
- Submission sub (If there is no submission with the ID = x)
- sub.Status1
- List item
提交子(如果没有提交ID = x)
PanelComment
Just change your code by the following:
只需通过以下方式更改您的代码:
Submission sub = String.IsNullOrEmpty(x) ? null : ss.getSubmissionByID(x);
if (sub!= null && sub.Status1 == 0){
...
It should fix most of the null references.
它应该修复大多数空引用。