5 Replies - 2445 Views - Last Post: 15 January 2012 - 03:37 PM Rate Topic: -----

#1 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,499
  • Joined: 16-March 11

Object Reference not set

Posted 13 January 2012 - 06:38 PM

So I've got myself a website which seems to crash on my iphone when I try to run it. The guys down where I work need a website they can log on to from their phones if they can't get to a pc. The website works, but the mobile one does not. It keeps displaying the error object reference not set to an instance. I've placed error codes in the code, and traced it to a line which has an object that is instanced, and uses the proper constructors. The second idea I had was that maybe it was one of my functions in that class, so I ran through it and placed errorcodes, and there are no objects that are not instanced in the function. I can't seem to figure it out. Does anyone know what the limitations of asp.net are for mobile phones? Or maybe some cans and can't do's for it? I can't exactly do a line trace on the page cause it only presents the error on the mobile web browser.

I've narrowed it down to my cookie methods of detection, placement, and deletion. More information soon. There's definitely something different about cookies on these mobile phones.


Scratch that. It's something to do with SQL. I guess I'm going to have to create some kind of work around for my database interaction.

After scavenging my code like a maniac looking for his marbles, I found no error in my code, and was led on a wild goose hunt. I found that when i commented out my cookie function it worked just fine. I'm going to dig into it more, can't see how my perfectly instanced cookie is creating so many errors. When I find the error I'll post my cookie code, so that others can avoid the simple error as I'm sure it's right in front of me!

This post has been edited by trevster344: 13 January 2012 - 06:57 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Object Reference not set

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,662
  • Joined: 02-June 10

Re: Object Reference not set

Posted 14 January 2012 - 10:45 AM

Object reference not set to the instance of an object.
Just like it sounds, you have a variable that you never assigned a value to.
Code execution stopped on that line. You just have to check which variable.

More detail in the very first link:


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Form1 talk to Form2



FAQ (Frequently Asked Questions - Updated Jan 2012

Spoiler

Was This Post Helpful? 1
  • +
  • -

#3 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,499
  • Joined: 16-March 11

Re: Object Reference not set

Posted 14 January 2012 - 11:14 AM

There are no errors in my code for my cookie object it has something to do with the way cookies are written to iPhones. This error Is something I'm particularly good at avoiding. I commented out my cookie code and will take a look at it another time.

This post has been edited by trevster344: 14 January 2012 - 12:37 PM

Was This Post Helpful? 0
  • +
  • -

#4 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,499
  • Joined: 16-March 11

Re: Object Reference not set

Posted 15 January 2012 - 02:53 PM

I cannot seem to spot where the error would come up in this code.


    Private Sub HasCookies(ByVal first As String, ByVal last As String)
        Try
            If Request.Cookies.Get("ARTCookie") Is Nothing Then


                Dim newcookie As New HttpCookie("ARTCookie", DropDownList1.SelectedValue)
                newcookie.Expires = Date.Now.AddDays(1)
                Response.Cookies.Add(newcookie)

            Else
                If Not Request.Cookies.Get("ARTCookie").Value.Equals(Global.Admin.GlobalUsername) Then


                    Dim NewUser As New User(Global.Admin.GlobalUsername, Global.Admin.GlobalPassword)
                    Global.Admin.WriteSpoofer(first & " " & last, Date.Now.ToString, DropDownList1.SelectedValue)

                    Request.Cookies.Get("ARTCookie").Expires = Date.Now.AddDays(-1)
                End If
            End If
        Catch ex As Exception
            Global.Admin.GlobalErrorMessage = ex.Message & " HasCookies"
        End Try
    End Sub



I tried commenting out my custom object to see if it went away, so it has something to do with the cookie object, and values I'm retrieving. Can anyone spot where I might be getting the object reference not set error from?
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,662
  • Joined: 02-June 10

Re: Object Reference not set

Posted 15 January 2012 - 03:23 PM

[ deleted ]

I see I already sent that link.

Did you look at the first link from my post above?
It will show you exactly which object is null

This post has been edited by tlhIn`toq: 15 January 2012 - 03:25 PM

Was This Post Helpful? 1
  • +
  • -

#6 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,499
  • Joined: 16-March 11

Re: Object Reference not set

Posted 15 January 2012 - 03:37 PM

I finally found it! Thanks man I appreciate it. The dang thing kept erroring even when I commented out my object, but it turns out it was my getlastname function. I've made it a habit to declare every variable for any object I am going to use, or may potentially use, but I wasn't aware not instancing it was so harmful after declaring it. I thought it was okay to have an object not instanced until I was going to use something that was apart of that object, which of course before this i would finally instance it.

This post has been edited by trevster344: 15 January 2012 - 03:43 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1