Problem defining a constant in java

  • Context: Java 
  • Thread starter Thread starter stonecoldgen
  • Start date Start date
  • Tags Tags
    Constant Java
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
4 replies · 2K views
stonecoldgen
Messages
108
Reaction score
0
I have:

Code:
public final static int NUMERO_ESCENARIOS=4;

escenarios = new escenario[NUMERO_ESCENARIOS];

having an error in the first line that says: Syntax error on token ";", , expected


but when I have:
Code:
public final static int NUMERO_ESCENARIOS=4 //semi colon deleted

escenarios = new escenario[NUMERO_ESCENARIOS];

I get no error in the definition of the constant but I obviously get a syntax error in the array definition

and when I have:

Code:
public final static int NUMERO_ESCENARIOS=4;

//array definition errased

the constant definition is fine





so what the hell is happening? thanks
 
Physics news on Phys.org
Have you defined "escenario" as a class? (by the way, it is considered good Java practice to spell you classes with an initial upper case letter).
 
Filip Larsen said:
Have you defined "escenario" as a class? (by the way, it is considered good Java practice to spell you classes with an initial upper case letter).

yes, and now that you mention it, I found out that escenario was actually Escenario (so I changed everything in my code to have that uppercase)

however, I still have the initial problem
 
stonecoldgen said:
I have:

Code:
public final static int NUMERO_ESCENARIOS=4;

escenarios = new escenario[NUMERO_ESCENARIOS];

having an error in the first line that says: Syntax error on token ";", , expected

If Escenario is a class, why are you using square brackets (which are used to access an array or List element) to pass NUMERO_ESCENARIOS to the constructor method? Shouldn't you have something like

Code:
public final static int NUMERO_ESCENARIOS=4;

Escenario escenarios = new Escenario(NUMERO_ESCENARIOS);

instead?
 
Or, if you are trying to create an array of Escenario objects, then you would first need to define escenarios to be an Array variable of type Escenario:

Code:
public final static int NUMERO_ESCENARIOS=4;

Escenario[] escenarios = new Escenario[NUMERO_ESCENARIOS];