WPF “System.Reflection.TargetInvocationException”类型的未经处理的异常出现在 PresentationFrame

hellobocai2020 2015-12-25 10:01:09
我的程序时一个WPF的播放器应用程序。目前碰到一个如标题所示的错误。

我自己写了一个Player.cs

public Player( Dispatcher dispatcher, IListener listener, int i )
{
this.listener = listener;
this.dispatcher = dispatcher;
window_id = i;
}

其次在MainWindow.xaml.cs中创建实例:

private Player mediaplayer1 = null;

在程序内部对其进行赋值

mediaplayer1 = new Player(this.Dispatcher, this, 1);

如果赋值这句语句放在InitializeComponent();之前就不会有错,放在InitializeComponent();之后就会出错。

调试后输出栏输出内容如下:
在 System.NullReferenceException 中第一次偶然出现的“WPF.exe”类型的异常
在 System.NullReferenceException 中第一次偶然出现的“System.Xaml.dll”类型的异常
在 System.NullReferenceException 中第一次偶然出现的“PresentationFramework.dll”类型的异常
在 System.Reflection.TargetInvocationException 中第一次偶然出现的“mscorlib.dll”类型的异常
在 System.Reflection.TargetInvocationException 中第一次偶然出现的“mscorlib.dll”类型的异常
在 System.Reflection.TargetInvocationException 中第一次偶然出现的“System.Xaml.dll”类型的异常
在 System.Reflection.TargetInvocationException 中第一次偶然出现的“PresentationFramework.dll”类型的异常
“System.Reflection.TargetInvocationException”类型的未经处理的异常出现在 PresentationFramework.dll 中。


大神们帮帮忙呀


...全文
1059 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
z643388838t 2016-02-29
  • 打赏
  • 举报
回复
InitializeComponent();执行后,才有控件
hellobocai2020 2015-12-25
  • 打赏
  • 举报
回复
hellobocai2020 2015-12-25
  • 打赏
  • 举报
回复
自己调查出来了。在程序起来的时候有个地方使用了mediaplayer1,为空则报错了。哎、、、
hellobocai2020 2015-12-25
  • 打赏
  • 举报
回复
回帖撒分

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧