Results 1 to 3 of 3

Thread: [02/03] Confused in creating Object reference

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006

    Talking [02/03] Confused in creating Object reference

    I want to display customer's information when user enters his number. But it gives an error
    Object reference not set to an instance of an object.
    i don't know how to do it. all other things are fine. what should i do here??

    VB Code:
    1. Dim objCustomer As MyCustomers = MyCustomers.GetCustomerByNo(CType(AskNo.Text, Long))
    2.             lblCustomerNo.Text = Convert.ToString(objCustomer.CustomerNo)
    3.             lblCustomername.Text = objCustomer.Customername
    4.             lblRecordId.Text = Convert.ToString(objCustomer.RecordId)
    5.             lblRecordDate.Text = Convert.ToDateTime(objCustomer.RecordDate)

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002

    Re: [02/03] Confused in creating Object reference

    Which line has the error, the first one? Are you familiar with using Shift+F9 to examine the contents of a variable or statement? If so, you should be able to narrow down exactly which object is not being initialized.
    My usual boring signature: Nothing

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: [02/03] Confused in creating Object reference

    There is no reason to ever be asking here about a NullReferenceException. There is nothing in that code that indicates where the issue is anyway. When the exception is thrown the debugger will tell you exactly which line it was thrown on. You can then test every reference on that line to see which one is Nothing, using Shift+F9 as Shaggy suggests or one of the many other ways the IDE provides that information (Locals, Autos, Watch, Immediate windows). Once you know what variable is referring to Nothing you simply work backwards through your code until you reach the point that you thought that that object should have been created. You don't debug code just by looking at it. You watch it in action. Set a breakpoint at the beginning of a section of code and step through the code line by line. What you're asking is like a mechanic just looking at a car, maybe lifting the bonnet, and expecting know what's wrong. You might see the really obvious stuff but usually you have to run the thing and see how it performs under real conditions.

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