Problem defining a constant in java

  • #1
107
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
 

Answers and Replies

  • #2
Filip Larsen
Gold Member
1,275
209
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).
 
  • #3
107
0
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
 
  • #4
gabbagabbahey
Homework Helper
Gold Member
5,002
6
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?
 
  • #5
gabbagabbahey
Homework Helper
Gold Member
5,002
6
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];
 

Related Threads on Problem defining a constant in java

Replies
4
Views
87
  • Last Post
Replies
2
Views
4K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
2
Views
2K
Replies
2
Views
843
Replies
2
Views
1K
Replies
4
Views
2K
  • Last Post
Replies
2
Views
1K
Replies
16
Views
3K
Top