-1
我有我的GetBuffer方法ArrayIndexOutOfBoundsException異常錯誤,緩衝ArrayIndexOutOfBoundsException異常錯誤
public class BufferPool {
private LPQueue<Buffer> queue;
private RandomAccessFile disk;
private int blockSize;
private int poolSize;
private Buffer[] pool;
public BufferPool(File file, int bufferNumber, int blockSize)
throws IOException {
this.blockSize = blockSize;
queue = new LPQueue<Buffer>(bufferNumber);
disk = new RandomAccessFile(file, "rw");
poolSize = ((int) disk.length()/blockSize);
pool = new Buffer[poolSize];
}
public Buffer getBuffer(int index) {
if (pool[index] == null) { // <<----------here!
pool[index] = newBuffer(index);
}
return pool[index];
}
}
能否請你幫我解決這個問題呢? 此緩衝池是緩衝池,用於存儲數據值 以便稍後對其進行排序。 This get Buffer獲取緩衝區句柄,該緩衝區表示支持此BufferPool的文件 的索引塊。 index是我們想要獲取的塊的索引。 它返回該塊的緩衝區句柄。
可能重複[什麼導致java.lang.ArrayIndexOutOfBoundsException,我該如何防止它?](http://stackoverflow.com/questions/5554734/what-causes-a-java-lang-arrayindexoutofboundsexception-and-怎麼辦-I-防止-IT) – Raedwald 2015-03-12 13:54:49