Vb.net 获取NullReferenceException但无法找到原因?
我的目标是在VB中创建一个具有选项卡系统的web浏览器。由于我无法明确命名用户将使用的每个新选项卡,因此我必须进行更一般化的调用。以下是与我的btnGo冲突的代码:Vb.net 获取NullReferenceException但无法找到原因?,vb.net,browser,nullreferenceexception,Vb.net,Browser,Nullreferenceexception,我的目标是在VB中创建一个具有选项卡系统的web浏览器。由于我无法明确命名用户将使用的每个新选项卡,因此我必须进行更一般化的调用。以下是与我的btnGo冲突的代码: Dim thisBrowser As newWebBrowser = Me.tabBrowser.SelectedTab.Tag If txtAdressSearch.Text.Contains(".com") Or txtAdressSearch.Text.Contains(".net") Or txtAdressSear
Dim thisBrowser As newWebBrowser = Me.tabBrowser.SelectedTab.Tag
If txtAdressSearch.Text.Contains(".com") Or txtAdressSearch.Text.Contains(".net") Or txtAdressSearch.Text.Contains(".gov") Or txtAdressSearch.Text.Contains(".edu") Or txtAdressSearch.Text.Contains(".org") Then 'More to be checked for
thisBrowser.Navigate(txtAdressSearch.Text)
Else
thisBrowser.Navigate("https://www.google.com/search?sourceid=chrome-psyapi2&rlz=1C1ASAA_enUS445&ion=1&espv=2&ie=UTF-8&q=" + txtAdressSearch.Text)
End If
这是新的网络浏览器代码:
末级
每当我在txtAddressSearch中输入内容时,Visual Studio都会引发NullRefresenceException并高亮显示thisBrowser.NavigateTxtAddressSearch.Text。作为旁注,它表示对象引用未设置为对象的实例
有人知道这里有什么问题吗?谢谢。在调试了一个多小时后,我检查了我的代码,发现我遗漏了大部分代码。我把它都写了出来,效果很好。问题是标签没有被正确定义,在某些情况下,根本不是这样。标签没有返回任何内容
感谢所有帮助过我的人。@DourHighArch,啊,对不起。只是看到了相互冲突的标签。它的VBA。您的浏览器引用取决于是否在某处选择了一个选项卡以及包含有效对象引用的标记属性。看起来更像是VB.NET而不是VBAcode@Plutonix,始终选择了一个选项卡。至于Tag属性,我不能100%确定它是否有对象引用。我该如何检查它?它几乎肯定没有有效的对象,或者你不会得到错误。在NET中,分配后只需将鼠标悬停在标记或此浏览器上即可。另请参见@puropoix,当我将鼠标悬停在该浏览器上时,它没有显示任何内容,这可能是导致此问题的原因。我如何将标签设置为我想要的状态?
Public Class newWebBrowser
Inherits WebBrowser
Private Sub webBrowserComplete() Handles Me.DocumentCompleted
Dim newTab As TabPage = frmBrowser.Tag()
Dim frmSK As New frmBrowser
Dim hi As String
newTab.Text = Me.DocumentTitle
frmSK.txtAdressSearch.Text = Me.Url.ToString
End Sub