0

当代码到达MessageBox.Show()时,它会引发异常Object reference not set to an instance of an object

这是我的代码:

WebBrowser webb = new WebBrowser();    
webb.Navigate("https://www.facebook.com/logout.php?next=http://facebook.com&access_token=" + Settings.Default["token"].ToString());

MessageBox.Show(webb.Url.AbsoluteUri.ToString());

你明白为什么会出现这种情况的原因吗?

4

1 回答 1

1

这可能有效:

WebBrowser webb = new WebBrowser();

private void pictureBox3_Click(object sender, EventArgs e)
{        
    webb.Url = new Uri("https://www.facebook.com/logout.php?next=http://facebook.com&access_token=" + Settings.Default["token"].ToString());
    webb.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted);        
}

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    MessageBox.Show(webb.Url.AbsoluteUri.ToString());
}
于 2013-05-21T16:14:23.440 回答