Vb.net 警告BC42104-赋值前使用的变量

Vb.net 警告BC42104-赋值前使用的变量,vb.net,Vb.net,我正在尝试从文件下载字符串,并收到以下警告 警告BC42104:变量“inst”在分配给 价值运行时可能会导致空引用异常 这是我的密码 Dim inst As WebClient Dim inst2 As WebClient Dim inst3 As WebClient Try MsgBox("started") ver = inst.DownloadString("http://www.xxxxxx

我正在尝试从文件下载字符串,并收到以下警告

警告BC42104:变量“inst”在分配给 价值运行时可能会导致空引用异常

这是我的密码

Dim inst As WebClient
        Dim inst2 As WebClient
        Dim inst3 As WebClient
        Try
            MsgBox("started")
            ver = inst.DownloadString("http://www.xxxxxxxxx.com/update/version.xml")
            loc = inst2.DownloadString("http://www.xxxxxxxxx.com/update/loc.xml")
            desc = inst3.DownloadString("http://www.xxxxxxxxx.com/update/description.xml")
            If (String.Compare(ver, String.Format(Nothing, My.Application.Info.Version.Major.ToString) + "." + String.Format(Nothing, My.Application.Info.Version.Minor.ToString)) = False) Then
                updreq = True
            End If
        Catch ex As Exception
            MessageBox.Show("Error occured: " + ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

该代码肯定会导致空引用异常。您已经声明了用于保存WebClient对象的变量,但尚未创建任何实际的WebClient实例

为变量创建WebClient类的实例:

Dim inst As WebClient = New WebClient()
或速记:

Dim inst As New WebClient()

我有一个类似的情况,我做了与上面相同的事情,只是为了一个标签页:

私有子btnAddTab_Clicksender作为对象,e作为事件args处理btnAddTab。单击 整数形式的数字=TabControl1.TabPages.Count 按TabPage调整选项卡=新建TabPage tab.Text=TabPage和number+1 TabControl1.TabPages.Addtab tab.BackColor=Color.DarkGreen 端接头