2

I'm working on some homework, and I'm not asking for help on how to solve it. For some reason Eclipse underlines parts of my code indicating something is wrong; yet provides no suggestion like it normally would. I haven't declared a multi-dim array in some time, so the syntax eludes me though I did google it. It appears correct according to the results I got.

This is what I found on google:

Initialising a multidimensional array in Java

For this class we are using a method of feeling the walls around you to find a path to follow, and marking where we have been with X's in an ASCII maze. #'s are walls, '.''s are paths, and 'F' is the finish point.

EDIT: After getting an answer, I wanted to post what the syntax underlining looked like so here: Underlining at line 2

Underlining at main() My code:

public class Maze {
    static char[][] tmp = new char [12][12];
    //First element is Y values (because X and Y lines are perpendicular)
    //First ROW (top)
    tmp [0][0] = '#';
    tmp [1][0] = '#';
    tmp [2][0] = '#';
    tmp [3][0] = '#';
    tmp [4][0] = '#';
    tmp [5][0] = '#';
    tmp [6][0] = '#';
    tmp [7][0] = '#';
    tmp [8][0] = '#';
    tmp [9][0] = '#';
    tmp [10][0] = '#';
    tmp [11][0] = '#';
    //Second Row
    tmp [0][1] = '#';
    tmp [1][1] = '.';
    tmp [2][1] = '.';
    tmp [3][1] = '.';
    tmp [4][1] = '#';
    tmp [5][1] = '.';
    tmp [6][1] = '.';
    tmp [7][1] = '.';
    tmp [8][1] = '.';
    tmp [9][1] = '.';
    tmp [10][1] = '.';
    tmp [11][1] = '#';
    //Third row
    tmp [0][2] = '#';
    tmp [1][2] = '.';
    tmp [2][2] = '.';
    tmp [3][2] = '.';
    tmp [4][2] = '#';
    tmp [5][2] = '.';
    tmp [6][2] = '.';
    tmp [7][2] = '.';
    tmp [8][2] = '.';
    tmp [9][2] = '.';
    tmp [10][2] = '.';
    tmp [11][2] = '#';

    //incomplete!

    public static void main (String [] args) {
        for(int i = 0; i != 12; i++) {

            for(int j = 0; j != 12; j++) {
                System.out.println(tmp[i][j]);
            }
            }
        }

    }

}

Keep in mind that I am just starting, and I'm unsure about what the array elements should contain where, so if the top actually goes down the left side, that is why. It won't even build now so I haven't been able to test it!

NOTE: I would post a picture of what Eclipse is showing underlined but I am unfamiliar with Stackoverflow's image linking/hosting. It looks like it take a link from another site; yet I really don't want to set up an account on a picture hosting site just for this and never use it again!

The portion which are underlined are:

Line 2 (where tmp is declared) at the very end, only beneath the semi-colon.

and

The line which declares the main method, specifically only beneath the

opening and closing parentheses.

Community
  • 1
  • 1
  • More info: I did just try copy & pasting in to a new file and it still does this :( –  Oct 25 '15 at 19:41
  • Statements such as `tmp [0][0] = '#';` must be inside a method. Move them to your main method. – Eran Oct 25 '15 at 19:42
  • By the way - it is much easier to initialise arrays using braces: `static char[][] map = { {'#', '#', '#', '#'}, {'#', '#', '#', '#'}, {'#', '#', '#', '#'}, {'#', '#', '#', '#'},};` – OldCurmudgeon Oct 25 '15 at 20:01
  • Why are you manually filling the array instead of using a proper constructor? `char[][] array ? { { 'r', 'o', 'w', '1' }, { 'r', 'o', 'w', '2' } }` – Clashsoft Oct 25 '15 at 20:01
  • as for "would post a picture of what Eclipse": http://meta.stackexchange.com/questions/75491/how-to-upload-an-image-to-a-post – Jonah Graham Oct 25 '15 at 20:04
  • @clashsoft I wasn't sure about the syntax, and the underlining/compilation problem prevented me from trying new syntax. That is why. –  Oct 25 '15 at 20:47

1 Answers1

5

Your assignments are outside of a method, constructor or an initialization block.

If you create a static initializer block static { tmp[0][0] = 'a'; // etc. } the code is valid. You can also put the code inside a method and call it at the start of your main method.

Kayaman
  • 72,141
  • 5
  • 83
  • 121