I'm using JUnit test intellij to test my code and I'm trying to debug an arrayOutOfBounds exception.
Fantastic news! We've Found the answer you've been seeking!
Question:
I'm using JUnit test intellij to test my code and I'm trying to debug an arrayOutOfBounds exception.
This is the test:
@Test void getElem() { Matrix m = new Matrix(new Scanner(simpleMatrix)); assertEquals(2, m.getElem(1,2), "getElem() did not return correct value"); }
This is getElem method:
public double getElem(int i, int j) { // return corresponding entry in matrix. return matrix[i][j]; }
This is the error I get when I try to run the getElem test:
java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
This is a matrix class for loading and modifying matrices. I'm quite lost on where the error is, as the only place it could be is in the getElem() according to the debugger. Can someone take a look?
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date: