Thread: getting instance object is null compile error in Visual Studios 2010 Express

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    20

    getting instance object is null compile error in Visual Studios 2010 Express

    Code:
     public class ColorGenetics
        {
            
            public static hk1Class jw;
            public static linkedClass link;
     
    
    
            static void Main(string[] args)
            {
                var jw = new hk1Class();
                var link = new linkedClass();
    
    
                program();
    
    
            }
    Code builds fine but compiler says I tried to use bject link w/o providing an instance.

    Class linkedClass has an instance of Class hk1Class set to var jw1.
    I had linkedClass useing the same var jw for the object instance. I changed it to jw1 thinking that would clear it up and it didn't.

    How do I correct it?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Why are you using the 'var' keyword there? That's used to define an implicitly typed variable. Just get rid of the vars since you already have them defined in the class scope.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    20
    ok. I got rid of the vars and was getting unhandled exception error.
    I did some reading about C# can only inherit from a base class but can indirectly inherit thru other classes.
    So I moved the ref to linkedClass into the base class and no more error.

    I will need to do more debug testing to see if I am accessing linkedClass. 1st I've got to tighten up user input error trapping to catch another error I just noticed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual C++ 2010 Express - difference from 2008?
    By ulillillia in forum Tech Board
    Replies: 26
    Last Post: 08-01-2011, 09:08 PM
  2. Compiler Error in Visual Studios 2010
    By ScottyK in forum C++ Programming
    Replies: 5
    Last Post: 11-21-2010, 12:54 PM
  3. Replies: 2
    Last Post: 08-28-2010, 12:58 AM
  4. Visual C++ 2010 express problems
    By dnj23 in forum Windows Programming
    Replies: 6
    Last Post: 08-10-2010, 06:16 AM
  5. Compile Error in Visual C++ 2005 express
    By Fremontknight1 in forum C++ Programming
    Replies: 9
    Last Post: 10-19-2007, 04:28 PM