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

Posted on 2006-05-09
Last Modified: 2013-11-26
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

It stops on the first line, but I'm stuck on what it means!

Thanks for any help!
Question by:tmccrank
    LVL 10

    Expert Comment

    by:Andrew Beers

    Requires that you have defined DA

    If you have not defined DA then this will not work because DA is being treated as an object refrence it is declaring that it is not set to any known instance of an object.  

    Let me know if this helps.


    Author Comment

    Thanks Aqua,

    I defined DA at the form level (if that's the right term) since I wanted it to be in scope for all the methods in the Class.

    That is, just below the Web Form Designer Generated Code block, I did this:

    Dim DA As DAL NurseEdMods.DataAccess

    Is that what you meant by defining DA?

    LVL 10

    Accepted Solution

    You might want to double check your syntax there.  VBScript gets very picky on where you use as and where you use set.  I think your best option here is to double check your objects with MSDN and check in their sample code.  Without weeding through your entire code I'm not very likely to decipher your exact problem.  But with that line throwing an error you have one of two problems:

    DA is undefined


    You need to instance alDD before assigning it to the return property of DA.PopulateDropDown()

    I'm leaving work shortly and will be unavailable to post for a few hours however if you'd like to post your code for this I'll dig through it to see what I can find.  ((This isn't one of my strongest langauges but I can muddle through it))


    Author Comment

    ...Sorry, DAL NurseEdMods.DataAccess should read DAL_NurseEdMods.DataAccess.

    Author Comment

    Thanks... I just realized that there's a seperate VB.NET forum which I should have posted to.  I'll try it there and see what happens.
    Posting the rest of my code probably wouldn't help much (it seems to me, which isn't saying much) since the error is popping up right at the first line of code.  I set a breakpoint on it which should at least fire me to the PopulateDropDown() method in my Data Access Layer, but that's not happening.  Hm.  Anyway, I'll try it over in VB.NET.  Hopefully I can award you the points for the time you took to answer.
    Thanks again,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    This is about my first experience with programming Arduino.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    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

    10 Experts available now in Live!

    Get 1:1 Help Now