VB.Net에서 Webbrowser 구성 요소로 첫 HTML UI를 작성하려고합니다. 나는 마이크로 소프트 사이트에이 코드 예제탐색 할 때 웹 브라우저 컨트롤에서 NullReferenceException을 throw합니다.
https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.document(v=vs.110).aspx 발견 : 나는 시험에 그것을 넣어 때
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles Me.Load
WebBrowser1.DocumentText =
"<html><body>Please enter your name:<br/>" &
"<input type='text' name='userName'/><br/>" &
"<a href='http://www.microsoft.com'>continue</a>" &
"</body></html>"
End Sub
Private Sub webBrowser1_Navigating(
ByVal sender As Object, ByVal e As WebBrowserNavigatingEventArgs) _
Handles WebBrowser1.Navigating
Dim document As System.Windows.Forms.HtmlDocument =
WebBrowser1.Document
If document IsNot Nothing And
document.All("userName") IsNot Nothing And
String.IsNullOrEmpty(
document.All("userName").GetAttribute("value")) Then
e.Cancel = True
MsgBox("You must enter your name before you can navigate to " &
e.Url.ToString())
End If
End Sub
을, 대부분의 시간은 코드의이 부분에서 예외 'System.NullReferenceException'가 발생합니다 :
If document IsNot Nothing And
document.All("userName") IsNot Nothing And
String.IsNullOrEmpty(
document.All("userName").GetAttribute("value")) Then
때때로 작동하지만 대부분 작동하지 않습니다. 이 문제를 어떻게 해결할 수 있습니까? 나는 .Net 플랫폼에 매우 익숙하다. 철자가 틀린다면 유감스럽게 생각한다. 어떤 도움을 주셔서 감사합니다.
을 그 단락 ... [NullReferenceException이, 그리고 내가 어떻게 해결합니까 무엇의 – Codexer
가능한 중복 ?] (http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Codexer