0
private void label16_MouseEnter(object sender, EventArgs e)
{
    panelSummary.Show();
    StockInfo temp = Game.getStockByLabelName(label16.Text);
   // StockComp.Text = "Stock Company = " + temp.getStockName();// I got errors in this line
    lbDispStockPrice.Text = "Stock price = " + temp.getPrice();
    lbDispStock.Text = "Stock category = " + temp.getCategory();
    owner.Text = "Property Of " + temp.getBuyer();
}
4

2 回答 2

1

要在您指示的行上“停止异常”,请检查nullGetStockByLabelName

StockInfo temp = Game.getStockByLabelName(label16.Text);

if(temp != null)
{
     StockComp.Text = "Stock Company = " + temp.getStockName();//if temp is null then EX
     //...
}
else
       //do whatever is appropriate for the situation where StockInfo is null

StockComp.Text 可能导致错误。我认为这是TextBox在设计师中创建的不太可能。

于 2013-10-30T16:10:39.817 回答
0

确保这些引用中的每一个都不是null

panelSummary
temp 
lbDispStockPrice
lbDispStock
owner

我的猜测是temp因为其他似乎是视觉组件,这意味着在Game.getStockByLabelNamenull值传递给label16.Text.

这是调试器派上用场的地方......

于 2013-10-30T16:06:27.223 回答