0

I am using an array like this:

int selIntIndex = Integer.valueOf(selStringIndex);

        int[][] PreIntVal = new int[][]


                {
                 { selIntIndex,
                        2 },
                 {
                        selIntIndex,
                        3 },
                 {
                        selIntIndex,
                        1 } };

        PreIntVal[3][0] = PreIntVal[4][0] = 3;

        android.util.Log.d("StripedLog",
                Arrays.toString(Values.PreStringVal[3]));

But somehow the code never reaches the "log" statement. The problem is with this line: PreIntVal[3][0] = PreIntVal[4][0] = 3; because if I comment it out, it works.

Any suggestions?

1 Answer 1

3

This particular line PreIntVal[3][0] = PreIntVal[4][0] is causing ArrayIndexOutOfBoundsException. Look at the defined array's dimensions : new int[][] { { selIntIndex, 2 }, { selIntIndex, 3 }, { selIntIndex, 1 } };. It seems you are confused as to how to access the array elements using index , please go through Oracle tutorial.

The valid indexes for this array are [0,1,2][0,1].

Observe this diagram to understand how the indexes are mapped.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.