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,0 ,0 ,0 ,110 ,111 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,110 ,111 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }, new int[]{31 ,32 ,0 ,0 ,107 ,0 ,0 ,0 ,56 ,57 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,56 ,57 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }, new int[]{26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 ,26 }, new int[]{27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 ,27 }, }; 

Now I want another array to hold these arrays so I can choose a random jagged array from it.
I did:

int[][][] mapArray = {map0,map1..}; 

But it gives me a compiler error saying An object reference is required for the non static field, method, or property 'map0'
int[int[][]] doesnt work either

2
  • Does this have to be arrays? Why not put this data into a class where it can be used more easily? Or even a List? Commented Jul 6, 2015 at 14:52
  • This array is a representation of a map. I just want to know the index and the value to draw the map. So I just used a jagged array Commented Jul 6, 2015 at 14:53

1 Answer 1

1

You cannot refer to other instance fields when initializing an instance field. You'll need to initialize it in the constructor.

You are declaring the type of the object entirely correctly; there's nothing to change there.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.