1

I am having trouble accessing an array Boolean value such as the following...

boolean[][] sub = new boolean[][];
Object[] record = new Object[];

record[0] = sub;

if ( record[0][0][1] == false )
{
    // Do something
}

When I set a watch, I get Type of boolean and value of false. The compiler gives an error of array required, but Object found.

The record[] array is of type object but contains a boolean[][] array within each index. I have tried casting but it isn't working ( i.e. (boolean)record[0][0][1] ). Does anyone have ideas on how to access the boolean value?

5
  • definition of record please Commented Oct 10, 2014 at 19:28
  • post here record definition... Commented Oct 10, 2014 at 19:28
  • record definition post here please here Commented Oct 10, 2014 at 19:28
  • Did you try ((boolean[][])record[0])[0][1]? Commented Oct 10, 2014 at 19:28
  • A lot of code / information is need to come up to a correct wanted solution. Commented Oct 10, 2014 at 19:30

1 Answer 1

2

If each element of record is boolean, the casting should be done on the first access to that array:

if ( ((boolean[][])(record[0]))[0][1] == false )
{
    // Do something
}

Or better yet, instead of comparing to false, just evaluate the array's content:

if ( !((boolean[][])(record[0]))[0][1] )
{
    // Do something
}
Sign up to request clarification or add additional context in comments.

1 Comment

just remove the == false and put a ! infront

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.