• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unexpected errors; where is syntax wrong?  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why do I get these errors on compile:


 
Marshal
Posts: 4052
239
Clojure IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler is complaining because your class syntax is incorrect. If you have a look at the Java Tutorial: Declaring Classes you'll see what is and is not allowed where in a class.

In your case you have statements in the class body which is not allowed. Statements need to be inside a method.
 
Ranch Hand
Posts: 87
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Miley Johnson wrote:

Why do I get these errors on compile:



You are probably missing a ending ; or a }, somewhere in the class. Also you should declare your variables and your array before the constructor.
 
Sean Paulson
Ranch Hand
Posts: 87
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:The compiler is complaining because your class syntax is incorrect.


What he said. Unless you want some of those variables to be not be local variables then you can declare them before the constructor. Most of that code does need to be in a method though.
 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[pedantic]

Technically, lines 14 to 17 just need to be inside a code block, which may not necessarily be a method. For example if you just surround those lines with { }, that would make it an instance initialization block and the code would compile. You can also put that code inside a constructor, which isn't a method.

[/pedantic]
 
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest it is quicker to use an array initialiser. There is no risk of miscounting the size of the array, nor of leaving any elements uninitialised.
I would also suggest you shouldn't call a class character (surely Character because classes begin with CapitalLetters) to avoid confusion with another class of the same name.
I would also suggest that you shou‍ld get rid of the array and create a Stats class instead.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!