Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.NET:UDP beginreceive方法引发NullReferenceException_Vb.net_Udp - Fatal编程技术网

VB.NET:UDP beginreceive方法引发NullReferenceException

VB.NET:UDP beginreceive方法引发NullReferenceException,vb.net,udp,Vb.net,Udp,抛出nullrefereneceexception 如何在UDP中使用beginreceive方法?我犯了什么错误?这是您的完整代码吗?您尚未为UDPrecivingClient变量分配任何内容,因此在尝试使用它时会导致空引用。此外,UdpClient需要一些信息才能使用,例如侦听哪个端口 Public udpReceivingClient As UdpClient udpReceivingClient.BeginReceive(AddressOf MT_RX_Callback

抛出
nullrefereneceexception


如何在UDP中使用beginreceive方法?我犯了什么错误?

这是您的完整代码吗?您尚未为UDPrecivingClient变量分配任何内容,因此在尝试使用它时会导致空引用。此外,UdpClient需要一些信息才能使用,例如侦听哪个端口

   Public udpReceivingClient As UdpClient   
   udpReceivingClient.BeginReceive(AddressOf MT_RX_Callback, Nothing) 

打开Option Explicit的可能重复项对空引用没有帮助exception@MattWilko是的,你说得对。我不确定自己在想什么,除了“现在是早上5点,我已经起床太久了。”不管怎样,选择显式/严格是个好主意,我发现自己在许多答案中都发布了这个链接。
    Public udpReceivingClient As UdpClient = New UdpClient(port_number)