Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 21st, 2007, 09:45 AM
GS GS is offline
Authorized User
 
Join Date: Sep 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Object reference not set to an instance of an obje

I have the following chunk of code:

        private void PopulateGrids()

        {



            //Get project cache

            List<ProjectEnterpriseCustomFieldContainer> list = EnterpriseCustomFieldsStorege.GetInstance().Projec tEnterpriseCustomFields[

                new Guid(application.ActiveProject.GetServerProjectGui d())];





            Dictionary<string, ProjectEnterpriseCustomFieldContainer> allFields = new Dictionary<string, ProjectEnterpriseCustomFieldContainer>();



            list.ForEach(delegate(ProjectEnterpriseCustomField Container container) { allFields.Add(container.FieldName, container); });



            List<ProjectEnterpriseCustomFieldContainer> listStartUp = GetBindingList(allFields, htStartUp);

            List<ProjectEnterpriseCustomFieldContainer> listDelivery = GetBindingList(allFields, htDelivery);

            List<ProjectEnterpriseCustomFieldContainer> listReference = GetBindingList(allFields, htReference);

            List<ProjectEnterpriseCustomFieldContainer> listSPSS = GetBindingList(allFields, htSPSS);





            if (origlistSPSS == null)

            {



                origlistSPSS.AddRange(listSPSS.GetRange(0, 23));



                origlistStartUp = listStartUp;

                origlistReference = listReference;

                origlistDelivery = listDelivery;

            }

            }

I am getting an error "Object reference not set to an instance of an object" on the line origListSPSS.AddRange.

the list origList is declared as: List<ProjectEnterpriseCustomFieldContainer> origlistSPSS;

If anybody has any ideas that would be appreciated - I cannot see why I cannot add the elements to the list?



Thanks

GS
 
Old May 21st, 2007, 09:55 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You can't call the AddRange method on origListSPSS until it is instantiated.

List<ProjectEnterpriseCustomFieldContainer> origlistSPSS = new List<ProjectEnterpriseCustomFieldContainer>();

-Peter
 
Old May 21st, 2007, 10:00 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I just reallized that your code will fail now, because you are checking for origlistSPSS == null. Why are you doing that? Do you mean to check that it is empty? (origlistSPSS.Count == 0)

-Peter
 
Old May 21st, 2007, 10:11 AM
GS GS is offline
Authorized User
 
Join Date: Sep 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Doh! Please ignore - realised just as I posted the topic!

Thanks for the responses though!

Sorry
GS





Similar Threads
Thread Thread Starter Forum Replies Last Post
Object reference not set to an instance of an obje rturner003 ASP.NET 2.0 Professional 0 December 26th, 2006 08:30 PM
Object reference not set to an instance of an obje williadn General .NET 0 January 18th, 2005 05:39 PM
Object reference not set to an instance of an obje bekim Classic ASP Basics 1 August 9th, 2004 01:25 AM
Object reference not set to an instance of an obje DolphinBay VB.NET 2002/2003 Basics 6 June 28th, 2004 03:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.