我制作了一个程序来显示LTE设备信息。我遇到的问题是尝试仅显示设备名称时发生此错误“对象引用未设置为对象的实例。”
public void GetInfo()
{
Initialise();
var Info = Get("api/device/information");
LogMessage(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString());
LogMessage(string.Format("Device name:\n {0}", Info.SelectSingleNode("//response/devicename").InnerText)); //something wrong here?
}
错误:
System.NullReferenceException: Object reference not set to an instance of an object.
at HuaweiRouterTool.HuaweiRouter.GetInfo() in C:\Users\pxc\Desktop\HuaweiRouterTool-master\HuaweiRouter.cs:line 233
at HuaweiRouterTool.Program.DeviceInfo() in C:\Users\pxc\Desktop\HuaweiRouterTool-master\Program.cs:line 41
at HuaweiRouterTool.Program.Main(String[] args) in C:\Users\pxc\Desktop\HuaweiRouterTool-master\Program.cs:line 21
但是当我删除“设备名称”时,它会显示所有值。
public void GetInfo()
{
Initialise();
var Info = Get("api/device/information");
LogMessage(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString());
LogMessage(string.Format("Device name:\n {0}", Info.SelectSingleNode("//response").InnerText));
}
我在这里做什么错了?
答案 0 :(得分:0)
我已经解决了这个问题。
我将“ DeviceName”改为“ DeviceName”,并且现在可以使用。