Object reference not set to an instance of an Object...

Posted on 2006-05-09
Last Modified: 2010-04-23
If I had a nickel for everytime I got this error.... this one has had this noob guessing for a while though.

Here's my code in the Page_Load sub:

        ' the PopulateDropDown() method returns an ArrrayList from my DAL.
        Dim alDD As ArrayList = DA.PopulateDropDown()

        'populate Modules drop down list
        ddlModules.DataSource = alDD

The exception is thrown on the first line, but I'm obviously stuck on why.  The DA was dimmed at the form level (just below the Web Form Designer Generated Code block) so it would be in scope for all methods in that Class:

Dim DA As DAL_NurseEdMods.DataAccess

Thanks for any help!
Question by:tmccrank
    LVL 52

    Expert Comment

    by:Carl Tawn
    Time to dust off the debugger. Put a breakpoint on the line in question and double-check that DA is a valid object. If it is, then it may be a problem with what "PopulateDropDown()" is returning.

    Author Comment

    Thanks Carl,
    I tried the breakpoint, but the exception is thrown even before the debugger steps in to the PopulateDropDown() function, which tells me that it can't be that method.  Is this right?
    Anyway, during debugging DA is showing up as "Nothing".  But won't it be "Nothing" until the function returns an ArrayList?  Like I said earlier, it's not even going there.
    LVL 52

    Accepted Solution

    No, DA should be a valid object at this point. PopulateDropDown() is a method of whatever class DA is. So you need to look at the declaration of DA.

    Chances are you code says something like:

        Dim DA As SomeClass

    Rather than:

       Dim DA As New SomeClass()


       Dim DA As SomeClass = New SomeClass()

    Author Comment

    Dim DA As New DAL_NurseEdMods.DataAccess

    That fixed it.
    Thanks very much.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now