Objetc reference not set to instance of an object


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Objetc reference not set to instance of an object

  1. #1
    Jason Salas Guest

    Objetc reference not set to instance of an object

    This is the .NET error I hate the worst: "Object reference not set to an
    instance of an object."

    Anyone got any ideas why I would be properly instantiating a custom class I
    wrote, and I still get the above error?

    NewsStory item = new
    NewsStory(Request.Form["fname"].Trim(),Request.Form["lname"].Trim(),Request.
    Form["age"].Trim());

    The funny thing is, the default constructor I defined for the class uses the
    above signature, requiring those 3 parameters. So, I wrote a simpler
    constructor as a test:

    // the code
    public class NewsStory
    {
    public NewsStory()
    {}
    }

    ....and tried instantiating that one in code:

    NewsStory item = new NewsStory();

    ....and it worked perfectly.

    Got any fixes?





  2. #2
    Jason Salas Guest

    Re: Objetc reference not set to instance of an object

    never mind...i got it.


    "Jason Salas" <jason@kuam.com> wrote in message
    news:3f29b6e4@tnews.web.devx.com...
    > This is the .NET error I hate the worst: "Object reference not set to an
    > instance of an object."
    >
    > Anyone got any ideas why I would be properly instantiating a custom class

    I
    > wrote, and I still get the above error?
    >
    > NewsStory item = new
    >

    NewsStory(Request.Form["fname"].Trim(),Request.Form["lname"].Trim(),Request.
    > Form["age"].Trim());
    >
    > The funny thing is, the default constructor I defined for the class uses

    the
    > above signature, requiring those 3 parameters. So, I wrote a simpler
    > constructor as a test:
    >
    > // the code
    > public class NewsStory
    > {
    > public NewsStory()
    > {}
    > }
    >
    > ...and tried instantiating that one in code:
    >
    > NewsStory item = new NewsStory();
    >
    > ...and it worked perfectly.
    >
    > Got any fixes?
    >
    >
    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center