wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes class/interface/enum errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "class/interface/enum errors " Watch "class/interface/enum errors " New topic
Author

class/interface/enum errors

Reno Madrigal
Greenhorn

Joined: Sep 24, 2007
Posts: 18
Well i have about 30 of these errors and thats just awful, someday my teacher will slow down and actually teach us proper syntax until then I would appreciate some advise.



Here are my errors:

class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
class, interface, or enum expected
<identifier> expected
<identifier> expected
<identifier> expected
<identifier> expected
<identifier> expected
<identifier> expected
<identifier> expected
<identifier> expected
illegal start of type
class, interface, or enum expected
[ October 05, 2007: Message edited by: Reno Madrigal ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The line

}//END Primaries2008()

is a proximal cause of many of your errors -- you're closing the class body here, and so all the code afterwards appears outside of any class. This is why the compiler says it's looking for a class, interface, or enum -- your methods are appearing at the top level of the file.

Once you fix that, you've got a misplaced semicolon here:

public void beginPrimary();

Then later in the file, I start to see methods ending prematurely, leaving some statements outside any method body and such.

Here's a hint: never, ever write more than a dozen lines of code without compiling it. Write a few lines, get it to compile. Add some more, get *that* to compile. Build up your programs a piece at a time. That way if you get an error, you know it's due to the last small changes you made.

No one except beginning students tries to write code by typing it all in, then compiling it and watching a million errors pile up!

If I were you, I'd set this file off to the side and start over. First get this to compile:

public class Primaries2008 {
}

Then add an empty method, like



And make sure that compiles before you start to add code to the function. Whenever you add a few lines, compile it, run it if possible, and see if what happens matches what you expect. Add extra code (print statements, for example) just for testing purposes. Make sure you understand each line as it runs.


[Jess in Action][AskingGoodQuestions]
Jinny Morris
Ranch Hand

Joined: Apr 29, 2007
Posts: 101
Reno -

Also, it looks like you're trying to use AND and OR as operators; as far as I know, those keywords don't exist in Java. You need to use && and || for the Boolean and and or operators.

Even if it hasn't been assigned, you might check your textbook for things like operators and control constructs - they're probably explained in the text.

Nice to know where all the election results questions are coming from!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: class/interface/enum errors
 
Similar Threads
Fibonacci
Finished my so-called program with many errors
Why is this HashSet allowing duplicates?
equals and hashcode
Assignment does not make sense to me.