method call error

This is a discussion on method call error within the C# Programming forums, part of the General Programming Boards category; I'm getting "Error 1 An object reference is required for the non-static field, method, or property 'JWGenetics.Genetics.program()' e:\visual studio 2010\Projects\JWGenetics.cs ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    9

    method call error

    I'm getting
    "Error 1 An object reference is required for the non-static field, method, or property 'JWGenetics.Genetics.program()' e:\visual studio 2010\Projects\JWGenetics.cs 50 13 JW Genetics"

    on method program.
    How do I fix this? I do not want to be passing arg/param.


    Code:
    using System;
    using System.IO;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace JWGenetics
    {
      public class Genetics
        {
            //create list for sire data
            public List<int> siregtype = new List<int>();
            //create list for dam data
            public List<int> damgtype = new List<int>();
            public const int rows = 128;
            public const int columns = 7;
            // create sire & dam 2D arrays
            public int[,] siredata = new int[rows, columns];
            public int[,] damdata = new int[rows, columns];
            //create offspring 1D array
            public int[] offspring = new int[14];
    
            public Dictionary<string, int> colors = new Dictionary<string, int>();
            public string color; //name
            Dictionary<string, string> geneo = new Dictionary<string, string>();
            public string gtype;
    
            // declare color genes groups //        
            bool extension_normal = false; bool color_normal = false; bool steel = false; bool harlequin = false; bool orange = false; bool tort = false; bool chin = false; bool boolshaded = false;
            bool dbldshaded = false; bool himi = false; bool agouti = false; bool tan = false; bool self = false;
           // Vienna types flags
            bool vienna = false; bool vm = false; bool vc= false;
            //color flags
            bool brown = false; bool dilute = false; bool charlie = false; bool broken=false; bool rew=false;
    
            // data input holders
            public  int sen1, sen2, sa1, sa2, sb1, sb2, sc1, sc2, sd1, sd2, se1, se2, sv1, sv2;
            public int den1, den2, da1, da2, db1, db2, dc1, dc2, dd1, dd2, de1, de2, dv1, dv2;
    
            // declare counters //
            public  int sirecounter = 0;
            public int damcounter = 0;
            public int offspringcounter = 0;
    
            public static bool e_trap;
    
            public static void Main(string[] args)
            {
                
                program();
            }
    
           public void program()
            {
             
                setup_sire();
                setup_dam ();
                child_setup();
                //  child_calc();  // determine % of each pheneotype & output to screen
    
    
                return;
            }
    
           public void setup_sire()
            {
                // populate sire data array //
                sire_En_1();
                sire_En_2();
                sire_A_1();
                sire_A_2();
                sire_B_1();
                sire_B_2();
                sire_C_1();
                sire_C_2();
                sire_D_1();
                sire_D_2();
                sire_E_1();
                sire_E_2();
                sire_V_1();
                sire_V_2();
                sire_data_setup();
                return;
            }
         
            public  void sire_En_1()
            {
                // Sire's Broken dominant gene var. input sen1 .//
                
                Console.WriteLine("Please input '1' if 'En' or '2' if 'en' for the sire's dominant Broken gene");
                string line = Console.ReadLine(); // read string from console
    
                
               bool res1 = int.TryParse(line, out sen1);// try to parse the string as an integer
                if (res1 == true)
                {
                    
                    switch (sen1)
                    {
                        case 1:
                        case 2:
                            e_trap = false;
                            break;
                        default:
                            e_trap = true;
                            break;
                    }
                }
                // loop untill no error
    
                while (e_trap == true)
                {
                    input_err();
                    Console.WriteLine("Please input '1' if 'En' or '2' if 'en' for the sire's dominant Broken gene");
                    string line2 = Console.ReadLine(); // read string from console
                    
    
                    bool res2 = int.TryParse(line2, out sen1); // try to parse the string as an integer
                    if (res2 == true)
                    {
                      
                        if (sen1 == 1 || sen1 == 2)
                        { e_trap = false; }
                    }
    
    
                }
                // end of error trap
                e_trap = true;
    
                return;
            }

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    "program" is not static. You need either an instance of your class to call program on, or make program static.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    9
    Thanks for the tip on instance.

    I solved it by putting "Main" into a separate class and called "program" from it there.
    This allowed me to access all the other methods.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Winsock problem
    By Wolf` in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2010, 04:55 PM
  2. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  3. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21