当我尝试添加一个对象时,我遇到了问题。请帮助!!!!
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());
}
错误:
java.lang.ArrayIndexOutOfBoundsException: length=0; index=1
答案 0 :(得分:1)
BufferTotal.add(n, buffer2.clone());
此行导致错误。您试图直接在索引1处添加元素而不是0.使n = 0;并再做一次。
答案 1 :(得分:0)
我已将[{1}}替换为BufferTotal.add(int,byte[])
,并且应用程序正常运行。