how can i fix object referance not set to an instance of an object

i have this code and everythingworks fine untill i add candle1 to an array private tdimage[] candles;
public MainPage()
{
InitializeComponent();
}
private void start_Clicked(object sender, EventArgs e)
{
start.IsVisible = false;
start.IsEnabled = false;
candle1.IsEnabled = true;
candle1.IsVisible = true;
candle2.IsEnabled = true;
candle2.IsVisible = true;
candle3.IsEnabled = true;
candle3.IsVisible = true;
candle4.IsEnabled = true;
candle4.IsVisible = true;
candles[0] = candle1;
System.Diagnostics.Debug.WriteLine(candles[0].ToString());
// Timer timer = new System.Timers.Timer();
// 1000= 1 second , the timer will run every second
// timer.Interval = 1000;
// timer.Enabled = true;
// timer.Elapsed += Timer_Elapsed;
//timer.Start();
}
this line causes the problem
candles[0] = candle1;

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    where i defined "candles"?

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭

    I would imagine that you have declared candles as an array of tdimage, but you have not created/initialised it.

    So you need code something like:

    private tdimage[] candles;
    candles= new tdimage[10];
    

    You can now set candles[0] to something.

Sign In or Register to comment.