0

I'm getting an error in Eclipse when trying to initialize the following array in the initializing section of my class:

Color[] colors;
colors = new Color[4];

This is the error I'm getting:

Syntax error on token ";", , expected

Where ";" refers to the semicolon on the first line. Tried different variable types, gave the same error. Here's some code on the official JDK tutorial section that seems the same to me:

http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

Thanks in advance, guys.

0

1 Answer 1

6

This is a correct syntax and does compile.

(Maybe the line before is a problem. Can you post it too)

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

1 Comment

Some guy just posted something and then deleted it. This is what he posted: Color[] colors = new Color[4]; And for some reason, it works. Well thanks anyway to both! (FYI the line before was boolean Active; nothing of interest)

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.