I have replaced BufferTotal.add(int,byte[])
for BufferTotal.add(byte[])
and the application goes on correctly.
vector java java.lang.ArrayIndexOutOfBoundsException: length=0; index=1
-
14-07-2023 - |
Question
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 = record.read(buffer, 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)
track.play();
buffer2=buffer.clone();
BufferTotal.add(n, buffer2.clone());
n++;
throw new IndexOutOfBoundsException("RecandPlay:Error en la posicion "+n+" de "+BufferTotal.size());
}
The error:
java.lang.ArrayIndexOutOfBoundsException: length=0; index=1
La solution 2
Autres conseils
BufferTotal.add(n, buffer2.clone());
This line is causing error. You are trying to add element directly at index 1 instead of 0. Make n=0; and do it again.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow