Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

object reference not set to an instance of an object in Struct

Posted on 2014-10-23
8
Medium Priority
?
326 Views
Last Modified: 2014-10-23
I have a struct I created in it I have a PulseEnergy[] when I go to add to it I get an error
"object reference not set to an instance of an object"
Why?
 public struct My_ControllerMemoryLog
        {
            //public int numberofsurveys;
            public UInt32 EraseID;
            public DateTime downloadtime;
            public string technician;
            public string location;
            public UInt32 toolnumber;
            public UInt32 controllerserialnumber;
            public float toolsize;
            public string jobtype;
            public DateTime SurveyTime;
            public DateTime PulseSyncTime;
            public float numberofpulses;
            public float angle;
            public float azimuth;
            public float tgf;
            public float hoursleft;
            public float voltage;
            public UInt32 battused;
            public float temperature;
            public float tmf;
            public float dip;
            public int[] frame;
            public bool[] PulseJam;
            public bool[] PulsePing;
            public uint[] PulseEnergy;
            public int defaultLocationIndex;
            

        }

for (int j = 0; j < 13; j++)
                {
                    mClist.PulseEnergy[j] = Program.MainForm.myBus.surveydata[i].pulseenergy[j]; <----Error here
                    mClist.PulsePing[j] = Program.MainForm.myBus.surveydata[i].pulseping[j];
                    mClist.PulseJam[j] = Program.MainForm.myBus.surveydata[i].pulsejam[j];

                }
public My_ControllerMemoryLog mClist;

Open in new window

0
Comment
Question by:r3nder
8 Comments
 
LVL 20

Expert Comment

by:Peter Hutchison
ID: 40400160
Shouldn't line 40 where mClist is declared come before line 33, where it is used?
0
 
LVL 6

Author Comment

by:r3nder
ID: 40400168
it does I was just giving all the information - sorry for the confusion
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 40400178
Does this cure it, you haven't created a instance of mCList in the code you supply.
public My_ControllerMemoryLog mClist = new My_ControllerMemoryLog();
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 6

Author Comment

by:r3nder
ID: 40400196
no andy that didn't do  it, iit makes it all the way through until it hits the array
 mClist = new My_ControllerMemoryLog();
            int numberOfSurveys = (int)Program.MainForm.myBus.numberofsurveys;
            for (int i = 0; (i < Program.MainForm.myBus.numberofsurveys); i++)
            {
                mClist.technician = Properties.Settings.Default.Username;
                mClist.location = Properties.Settings.Default.Location;
                mClist.EraseID = Program.MainForm.myBus.Controller_EEProm[EEPROM.CONTROLLER.EraseID].Data.asLong;
                mClist.controllerserialnumber = Program.MainForm.myBus.Controller_EEProm[EEPROM.CONTROLLER.SerialNum].Data.asLong;
                mClist.toolnumber = Program.MainForm.myBus.Controller_EEProm[EEPROM.CONTROLLER.ToolNumber].Data.asLong;
                mClist.SurveyTime = Program.MainForm.myBus.surveydata[i].SurveyTimeStamp;
                mClist.PulseSyncTime = Program.MainForm.myBus.surveydata[i].PulseSyncTimeStamp;
                mClist.angle = Program.MainForm.myBus.surveydata[i].Angle;
                mClist.azimuth = Program.MainForm.myBus.surveydata[i].Azimuth;
                mClist.dip = Program.MainForm.myBus.surveydata[i].DipAngle;
                mClist.hoursleft = Program.MainForm.myBus.surveydata[i].BatteryHoursLeft;
                mClist.voltage = Program.MainForm.myBus.surveydata[i].BatteryVoltage;
                mClist.battused = Program.MainForm.myBus.surveydata[i].BatteryCountsUsed;
                mClist.temperature = Program.MainForm.myBus.surveydata[i].Temperature;
                mClist.tgf = Program.MainForm.myBus.surveydata[i].TGF;
                mClist.tmf = Program.MainForm.myBus.surveydata[i].TMF;
                mClist.numberofpulses = Program.MainForm.myBus.surveydata[i].numberofpulsessent;
                mClist.defaultLocationIndex = Program.MainForm.currentuser.defaultlocationid;
                for (int j = 0; j < 13; j++)
                {
                    mClist.PulseEnergy[j] = Program.MainForm.myBus.surveydata[i].pulseenergy[j]; <---Error here
                    mClist.PulsePing[j] = Program.MainForm.myBus.surveydata[i].pulseping[j];
                    mClist.PulseJam[j] = Program.MainForm.myBus.surveydata[i].pulsejam[j];

                }
                for (int k = 0; k < 11; k++)
                {
                    mClist.frame[k] = Program.MainForm.myBus.surveydata[i].frames[k];
                }
                list1.Add(mClist);
            }

Open in new window

0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 40400211
aha, same principle, you need to create all the arrays.

eg.
public int[] frame;
should be
public int[] frame = new int[99];  //or however many you want in the array

and so on
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 40400249
good catch thanks Andy - thank you
0
 
LVL 40
ID: 40400375
I would define a class instead of a structure in you case. Because of the way they are handled in memory, structures should be small objects. Microsoft recommends 16 bytes as the maximum. Your structure is way bigger than this suggested limit.
0
 
LVL 6

Author Comment

by:r3nder
ID: 40400473
Thanks Jacques I am doing  that now
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Loops Section Overview

885 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