Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Array declaration in a class  RSS feed

 
You Gin
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm faced with those two error messages while compilation for the simple class in which I'm declaring an array. Please advices why is it so.

Errors:
Description Resource Path Location Type
Syntax error on token ";", { expected after this token TwentyOneGame.java /TwentyOneGame/src line 15 Java Problem
Syntax error, insert "}" to complete ClassBody TwentyOneGame.java /TwentyOneGame/src line 24 Java Problem

Class:

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Other than declarations, all other types of statements must be within an initializer, constructor, or method.

Henry
 
You Gin
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True. It's fine now:

 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot fully explain why your getting the errors that your getting, but I can
make what your doing work. Maybe someone in the membership is willing to
give a detailed explanation. Here is what I tried, which works BTW on my
machine.

HTH,
Jeff.


 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
....and there you have it, thank to Henry.
How could this have worked utilizing the default constructor though?

 
You Gin
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, then I've changed the method to constructor
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually you had no method at all.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the third post there was method dec.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry OP, there was a dec.

G.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!