Object reference not set to an instance of an object (561204)

Hi
I’ve been doing some examples of loading a song and trying to detect its beats. Now I am getting there thanks to some articles I found online. Here is my question, while trying to get access to my own class FFT I got the error message as described on topic. Can someone tell me why this is happening? Thanks in advance. Here is my code, have a look.


usingUnityEngine;
usingSystem.Collections;

publicclassspec2 : MonoBehaviour
{
publicAudioSourcesong; //settheaudiosourcetodetect
float[ ] channelRight;
float[ ] channelLeft;
publicclassFFTElement
{
publicfloatre = 0.0f; //Realcomponent
publicfloatim = 0.0f; //Imaginarycomponent
publicFFTElementnext; //pointtonextelement
}

FFTElement[ ] _data = newFFTElement[1024];

voidStart ()
{
//allocateelementforlinkedlist
for(inti=0;i<1023;i++)
{
data = newFFTElement();
}
//setupnextpointer
for(inti=0;i<1023;i++)
{
data*.next = data[i+1];
_
}*

}
voidUpdate ()
{
for(intj=0;j<channelLeft.Length;j++)
{
channelRight = song.audio.GetSpectrumData(1024,0,FFTWindow.BlackmanHarris);
channelLeft = song.audio.GetSpectrumData(1024,1,FFTWindow.BlackmanHarris);
//computetheinstantsoundenergy
e = e + ((channelLeft[j]*channelLeft[j]) + (channelRight[j]*channelRight[j]));
historyBuffer = e; //inserteintobuffertostore
_data[j].re = channelRight[j];
_data[j].im = channelLeft[j];
}

}
}

  1. Use CODE Tags
  2. Please post the error message and stack trace
  3. It means exactly what it says. You are trying to access an object and you haven’t created an instance of it (it’s null).
1 Like

Hi, Dustin
Sorry for the mistakes i made here, and thanks for telling me. Because i am beginner here can you tell me how to use code tag? And the error message is “Object reference not set to an instance of an object”. And it told me that the error happened while running _data[j].re = channelRight[j]. I thought I did declare and new the class, but i didn’t know how can’t I use it.