【发布时间】:2012-12-11 15:34:48
【问题描述】:
获取异常信息:
对象引用未设置为对象的实例。
我的代码是:
PictureBox myPicBox = new PictureBox();
myPicBox.Visible = true;
myPicBox.Image = Bitmap.FromFile(@"C:\Users\MyUser\Downloads\1341596825343s1jpg.jpg");
myPicBox.Dock = DockStyle.Fill;
this.MyTabPage.Controls.Add(myPicBox);
其中MyTabPage 是选项卡控件中的第四页。有什么建议吗?
编辑:
堆栈跟踪在这里
在 ShipSiegeDashBoard.Form1.LoadSpaceStations() 中 C:\ShipSiegeTool\ShipSiegeDashBoard\Form1.cs:第 46 行 ShipSiegeDashBoard.Form1..ctor() 在 C:\ShipSiegeTool\ShipSiegeDashBoard\Form1.cs:第 31 行 ShipSiegeDashBoard.Program.Main() 在 C:\ShipSiegeTool\ShipSiegeDashBoard\Program.cs:第 18 行 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,字符串 [] 参数)在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback 回调、对象状态、布尔值 ignoreSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback 回调、对象状态)在 System.Threading.ThreadHelper.ThreadStart()
【问题讨论】:
-
您是否尝试过调试它并将其缩小到您的异常来自哪一行?您甚至可以尝试发布您的堆栈跟踪,这也会有所帮助。
-
你调试过你的代码吗?
-
您似乎遇到了空指针异常。在代码中添加断点并检查未设置哪个变量。它可以是您的标签页,也可以是它的控件。
-
我做了,错误来自添加控制线
-
你的代码是放在Form的构造函数中
InitializeComponent之前的吗?