C# 如何修复Xamarin';System.ArgumentNullException:';值不能为null。参数名称:地址';例外情况
构建和运行应用程序时,我得到一个“System.ArgumentNullException:”值不能为null。参数名称:地址“异常” 异常指向这段代码,指向初始化端点的行:C# 如何修复Xamarin';System.ArgumentNullException:';值不能为null。参数名称:地址';例外情况,c#,xamarin,udp,C#,Xamarin,Udp,构建和运行应用程序时,我得到一个“System.ArgumentNullException:”值不能为null。参数名称:地址“异常” 异常指向这段代码,指向初始化端点的行: public void sendInstruction(string instruction) { char[] charInput = instruction.ToCharArray(); Byte[] sendBytes = Encoding.ASCII.GetBytes(cha
public void sendInstruction(string instruction)
{
char[] charInput = instruction.ToCharArray();
Byte[] sendBytes = Encoding.ASCII.GetBytes(charInput);
IPEndPoint epWK = new IPEndPoint(ip, port);
udp.Send(sendBytes, sendBytes.Length, epWK);
}
所有参数都在以下步骤之前定义:
public IPAddress ip;
public int port;
UdpClient udp = new UdpClient();
并设置:
ip = IPAddress.Parse("192.168.178.62");
port = 54490;
代码以前工作过,所以我不理解为什么会触发此异常。可能在调用sendInstruction之前不会调用初始化ip的代码。它告诉您
ip
为空,调试并检查ip
的值,不要因为错误告诉您不是这样,就假定它不是空的。请发一封邮件,我们可以帮你。