private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Dictionary<string, LivePacketDevice> copyOfAdapters = find_adapter.Adapters;
copyOfAdapters.Remove(comboBox1.SelectedText);
Dictionary<string, LivePacketDevice> copyOfAdapters22 = copyOfAdapters;
}在启动项目之后,exeption被抛出。
System.NullReferenceException类型的一个例外发生在.但未在用户代码中进行处理。 附加信息:对象引用未设置为对象的实例。
在第一行方法的末尾。但是find_adapter是在表单的构造函数中创建的。那么错误在哪里呢?我真的不知道:/ THX
发布于 2015-10-07 19:27:53
我认为您应该添加检查空值,并尝试使用comboBox1.SelectedItem.ToString()而不是comboBox1.SelectedText。
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (find_adapter.Adapters == null || !find_adapter.Adapters.Any())
{
Dictionary<string, LivePacketDevice> copyOfAdapters = find_adapter.Adapters;
copyOfAdapters.Remove(comboBox1.SelectedItem.ToString());
var copyOfAdapters22 = new Dictionary<string, LivePacketDevice>(copyOfAdapter);
}
}https://stackoverflow.com/questions/33000538
复制相似问题