Results 1 to 11 of 11

Thread: WebKit URL

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2014
    Posts
    23

    WebKit URL

    I'm trying to get the url from the WebKit component. I've got this:
    Code:
    Url.text = WebKitBrowser1.Url.ToString()
    But it's giving me this:
    "Object reference not set to an instance of an object."

    It works with the normal Webbrowser...

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,242

    Re: WebKit URL

    When you get that exception, examine every object in the line. One of them is Nothing, and the first step is to find out which one. Here are the options in that line:

    1) Url. This is a possibility.
    2) Url.Text: This is not a possibility, because you are setting the property, so it doesn't matter whether or not it is Nothing to start with.
    3) WebKitBrowser1: This is a likely possibility.
    4) WebKitBrowser1.Url: This is also a likely possibility.
    5) WebKitBrowser1.Url.ToString(): This may not seem like an object, but it does return an object. However, it's not a possibility, because it wouldn't matter whether this returned Nothing or not (though, in fact, it can't return Nothing).

    Find out which one is Nothing, as that's the first step to solving this exception.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2014
    Posts
    23

    Re: WebKit URL

    I have tried:
    Url.Text = WebKitBrowser1.Url - Doesn't work
    Url.Text = WebKitBrowser1.Text - Doesn't exist

    The only thing that exists is Url.Text = WebKitBrowser1.Url.ToString

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,242

    Re: WebKit URL

    It doesn't matter whether it works or not, it matters whether you find the object that is Nothing. This exception is ALWAYS a simple one to solve, but you have to take that first step and find the object that is Nothing. If you aren't familiar with how to find out which object is Nothing, then ask about that.

    Once you know which object is Nothing, then the next step is to figure out why it is Nothing and fix that. Quite often, once you know WHICH object is Nothing, then WHY is a simple question to answer. Either something wasn't initialized, or something wasn't created, but you have to know which object is Nothing to figure that out.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2014
    Posts
    23

    Re: WebKit URL

    I'm sorry, I'm not familiar with Objects yet.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Dec 2014
    Posts
    23

    Re: WebKit URL

    Correct me if I'm totally wrong, but is this ok?

    If WebKitBrowser1.Url Is Nothing Then
    MsgBox("Nothing")
    End If

    I get the message box with "Nothing".

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,242

    Re: WebKit URL

    That's the hard way to do a one-off test, but it certainly works. That is how you would check to see whether the Url is Nothing prior to attempting to use it in code. If you are just testing, then you'd put a breakpoint on the line (like the line that caused the problem in the original post) and either hover your mouse over the object or highlight the object and press Shift+F9. Hovering the mouse is supposed to work, but it often doesn't for me, so I tend to use the Shift+F9 alternative most of the time. Hovering the mouse over the object should bring up a tooltip that shows the value of the object, it just doesn't always.

    In any case, you have tracked down the first step. Of the options I originally listed, if Option 3 had been the problem (WebKitBrowser1 was Nothing), then your code would have crashed, because attempting to access the .Url property of an object that is Nothing would cause the Object Reference not set exception. Since the code worked, you see that WebKitBrowser1 is NOT Nothing, but WebKitBrowser1.Url IS nothing. Attempting to call .ToString on an object that is nothing will give you that exception, so you have tracked it down correctly (unless my option #1 is also true, but that seems much less likely).

    So, now you need to figure out why the Url property is Nothing. I'm not much help on that, because I have no idea what WebKitBrowswer1 is, having never seen it before. It seems like that is a property that you would set to a Url to cause the browser to navigate to a site, or perhaps you set the Url and then do something else to navigate. Still, you appear to expect that the Url will have already been set by something. It hasn't been, so whatever you were expecting to have set it is not doing what you are expecting.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Dec 2014
    Posts
    23

    Re: WebKit URL

    I appreciate all of the info.
    I've hovering over Url, and the tool tip shows me "Public Property Url As System.Uri", so it's not giving me the value of the object.

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,242

    Re: WebKit URL

    Yeah, like I said, it often doesn't work for me, either. Except that by showing you the type, it sounds like you might be hovering over it when it isn't running, in which case it won't be anything but a type. On the other hand, I don't trust the tooltips anyways. If you have a standalone variable, then they seem to work pretty well. If you have a more complex statement, as you have, then the tooltip shows you what MS thinks you might want. Sometimes they are right, sometimes they are not. Highlighting the variable and pressing Shift+F9 is the solution that will work...mostly...when tooltips do not. The reason I say mostly, is that in some situations, the IDE gets confused about scope. I occasionally try to look at a variable only to have the IDE say that it isn't defined or accessible, which is totally wrong, but that tends to happen when working through dll calls.
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Dec 2014
    Posts
    23

    Re: WebKit URL

    Opps it wasn't running.
    When I hover over Url, I'm now getting:
    WebKitBrowser1.Url | Nothing

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,242

    Re: WebKit URL

    Cool, so the tooltip worked for you. In any case, you have now identified the source of the problem. The next step is to figure out the cause, but we can't help all that much without seeing whatever it was you did that made you think that the Url would be something rather than Nothing. Did you navigate the browser somewhere or do something like that?
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width