bishop_1414 bishop_1414 - 2 years ago 183
Java Question

vector java java.lang.ArrayIndexOutOfBoundsException: length=0; index=1

I have a problem when I'm trying to add one object. Please Help!!!!

Vector BufferTotal = new Vector();
int n=1;

while (true) {
if(AudioRecord.ERROR_INVALID_OPERATION != 0) {
num =, 0, 1024);
track.write(buffer,0, num);
//Writes the audio data to the audio sink for playback (streaming mode),
//or copies audio data for later playback (static buffer mode);
BufferTotal.add(n, buffer2.clone());
throw new IndexOutOfBoundsException("RecandPlay:Error en la posicion "+n+" de "+BufferTotal.size());


The error:
java.lang.ArrayIndexOutOfBoundsException: length=0; index=1

Answer Source

I've solved it. I've replaced BufferTotal.add(int,byte[]) for BufferTotal.add(byte[]) and the application goes on correctly. Thanks!!!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download