• Post Reply Bookmark Topic Watch Topic
  • New Topic

Class or interface expected + is my code ok.  RSS feed

 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So starting of the parts of this code that are in CAPS have an error of 'Class' or 'Interface' expected. (FYI: They are not in caps in the actual code.)
(Look for: WELCOME TO POKEMON, GO...., THE ENEMY FAINTED + YOU FAINTED. These are all the 'Class' or 'Interface' expected stuff)
And also is my code ok?

 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bod McLeon wrote:So starting of the parts of this code that are in CAPS have an error of 'Class' or 'Interface' expected. (FYI: They are not in caps in the actual code.)


Syntax errors are compiler errors. And compilers errors are much more specific than that, with line numbers, pointers to the location. etc. Perhaps you can show us the complete error from the compiler?

Henry
 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Bod McLeon wrote:So starting of the parts of this code that are in CAPS have an error of 'Class' or 'Interface' expected. (FYI: They are not in caps in the actual code.)


Syntax errors are compiler errors. And compilers errors are much more specific than that, with line numbers, pointers to the location. etc. Perhaps you can show us the complete error from the compiler?

Henry

The thing is when I run it it gives no errors it is only when I hover over it that it says  'Class' or 'Interface' expected.
(I use IntelliJ Idea)
When it is run it says:
Process finished with exit code 0.
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bod McLeon wrote:
The thing is when I run it it gives no errors it is only when I hover over it that it says  'Class' or 'Interface' expected.
(I use IntelliJ Idea)
When it is run it says:
Process finished with exit code 0.


First of all, never run code that doesn't compile. This is actually not allowed by the JDK, but IDEs tend to allow it because it is sometime convenient to test parts of a program, with other parts that are broken.

The problem, however, is that it is not specified by the JLS. When the IDE compiler encounters issues, it just tries to patch around it with a statement that it found an error. And when the compiler gets completely confused, it just creates a mess.

Please read this... https://coderanch.com/wiki/660183/Wiki/Fix-Compiler-Errors-Running-Application


And BTW, from the code that you posted, you do seem to have class declarations inside methods (that are not method local inner classes).... so, this is likely the source of the compiler errors.

Henry
 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

And BTW, from the code that you posted, you do seem to have class declarations inside methods (that are not method local inner classes).... so, this is likely the source of the compiler errors.

Henry

I get really confused with this stuff. So on which line(s) do I have class declarations inside methods?
 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also Btw these errors only popped up today and I have had this code with class declarations inside methods for a couple of days and that has confused me more.
 
Julian West
Ranch Hand
Posts: 91
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bod McLeon wrote:


Did you mean to have the main method empty?
 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Julian West wrote:
Bod McLeon wrote:


Did you mean to have the main method empty?

What would I put in it though?
 
Bod MacNeil
Ranch Hand
Posts: 62
2
Java Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool name :P
 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bod MacNeil wrote:Cool name :P

Firstly is that mean to be because we have the same name?
If it is not which parameters would 'x name of something' go in for the main method?
 
Julian West
Ranch Hand
Posts: 91
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bod McLeon wrote:
Did you mean to have the main method empty?

What would I put in it though?

Umm...er...code.  That particular main method is where the program starts.  It's the "START HERE" point.

Forget the compiler for a moment and compile/run your code from the command line.  It compiles just fine and runs just fine...it runs just like a program not told to do anything:

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