I am trying to simply print out a 2D array. But I am getting an error

Eclipse is telling me that, "The type of the expression must be an array type but it resolved to Theater"(The class for the object I created for my 2D array) on the last line of code I have below. Specifically here --> a[row]

This is just one small piece of a larger project I am working on in my Java class. You all may be familiar with it, I have to print and implement a theater seating chart using a 2D array. I have to write methods for searching by price, searching by seat, etc. Right now I am just trying to initialize the 2D array, put some values in it then print them out. Any help is much appreciated.

public class Theater { //int[][] x = new int[9][10];    int y[][];      public Theater(){         //Initialize array         for (int row = 0; row < 3; row++)             for (int column = 0; column < 10; column++)                 y[row][column] = 10;     }      public static void main(String[] args){         Theater a = new Theater();          for(int i = 0; i < 3; i++)             for (int row = 0; row < 9; row++)                 for (int column = 0; column < 10; column++)                     System.out.println(a[row][column]); 


The [] operator needs to be applied to a expression that is an array. Since Theater is not an array, you get a compile time error. You probably wanted to access the y field of the Theater instance:


Furthermore you need to create the y array before using it:

public Theater(){
    this.y = new int[3][10];

Category: java Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C) avrocks.com, All Rights Reserved.

processed in 3.094 (s). 13 q(s)