【问题标题】:vector java java.lang.ArrayIndexOutOfBoundsException: length=0; index=1向量 java java.lang.ArrayIndexOutOfBoundsException: 长度=0;索引=1
【发布时间】:2014-05-03 09:02:50
【问题描述】:

我在尝试添加一个对象时遇到问题。请帮忙!!!!

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

【问题讨论】:

  • 请从 logcat 发布堆栈跟踪。
  • 别担心,我已经解决了。我已经将 BufferTotal.add(int,byte[]) 替换为 BufferTotal.add(byte[]) 并且应用程序正常运行。谢谢!!!

标签: java android arrays vector indexoutofboundsexception


【解决方案1】:
BufferTotal.add(n, buffer2.clone());

此行导致错误。您正在尝试直接在索引 1 而不是 0 处添加元素。 Make n=0;然后再做一次。

【讨论】:

  • 没有。我之前尝试过,但问题仍然存在。
【解决方案2】:

我已将BufferTotal.add(int,byte[]) 替换为BufferTotal.add(byte[]),并且应用程序正常运行。

【讨论】:

    猜你喜欢
    • 2023-04-10
    • 2021-05-29
    • 2019-07-27
    • 2018-09-21
    • 1970-01-01
    • 2022-12-18
    • 1970-01-01
    • 1970-01-01
    • 2018-11-05
    相关资源
    最近更新 更多