gpt4 book ai didi

c# - 抛出 NullReferenceException?

转载 作者:太空宇宙 更新时间:2023-11-03 11:03:09 27 4
gpt4 key购买 nike

我得到这个异常:

NullReferenceException
Object reference not set to an instance of an object
at Namespace.TheClass.TheMethod()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

在这段代码中:

public class TheClass : TheBaseClass
{
protected IList1 List;
public object Object1;
public ManualResetEvent MrEvent = new ManualResetEvent(false);
readonly Attr1 Attr1;
readonly Attr2 Attr2;
readonly EventHandler<Class1> BeginHandler, EndHandler;
readonly EventHandler<Class2> Handler2;
readonly EventHandler<Class3> Handler3;

public TheClass(Attr1 attr1, Attr2 attr2, EventHandler<Class1> beginHandler, EventHandler<Class1> endHandler, EventHandler<Class2> handler2, EventHandler<Class3> handler3)
{
this.Attr1 = attr1;
this.Attr2 = attr2;
this.BeginHandler = beginHandler;
this.EndHandler = endHandler;
this.Handler2 = handler2;
this.Handler3 = handler3;
Thread t = new Thread(Run);
t.IsBackground = true;
t.Start();
}

void TheMethod()
{
Args1 args1 = new Args1();
if (BeginHandler != null)
{
try
{
BeginHandler(this, args1);
}
catch { }
}

try
{
List = GetList(args1);
}
catch { }

if (List != null)
{
List.Event1 += new EventHandler<Args2>(List_Event1);
}

if (Handler3 != null)
{
try
{
Args3 args3 = new Args3(args1.Attr1, args1.Attr2);
Handler3(this, args3);
this.Object1 = args3.Object1;
}
catch { }
}

if (this.Object1 == null)
{
if (args1.Attr1 != null)
try
{
this.Object1 = Class4.GetObject(args1.Attr1);
}
catch { }
}

MrEvent.Set();
Method1();
Method2();

if (List != null)
{
List.Event1 -= new EventHandler<Args2>(List_Event1);
}

if (EndHandler != null)
{
try
{
EndHandler(this, args1);
}
catch { }
}
}
}

我没有看到任何可以抛出上述句柄空异常的地方。你看到任何人了吗?

Veer:你怎么能把我的问题的意思改变这么多?
对赞成它的人:你怎么会赞同它?

最佳答案

NullReferenceException 可以从内联方法中抛出。查看方法 1 和方法 2。

关于c# - 抛出 NullReferenceException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16913839/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com