aspose file tools*
The moose likes Beginning Java and the fly likes First question in Beginners forum ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "First question in Beginners forum ... " Watch "First question in Beginners forum ... " New topic
Author

First question in Beginners forum ...

Tonya Cash
Greenhorn

Joined: Feb 18, 2005
Posts: 2
Hi Everybody,

I am working through the 2nd edition book Head first Java, and trying to figure out the following example code. As far as I can tell, everything is ok. Other classes compile fine, so I know it's not my PATH or CLASSPATH or anything like that. I have checked my brackets, and I am hoping someone here can see something I can't. Any Ideas?

Thank you!
- Tonya

I am getting this error:
SimpleDotCom.java:1: 'class' or 'interface' expected
public static void main(String[] args) {

when I try to compile the following code:
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

A method (like main) needs to be a member of a class or interface. So the compiler is telling you that you need to enclose your code within a class definition...



"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Tonya Cash
Greenhorn

Joined: Feb 18, 2005
Posts: 2
Thank you Marc! I see exactly what you mean ...
-Tonya
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Actually, now that I look at this in more detail, it appears the classes SimpleDotCom and GameHelper are probably defined elsewhere. So rather than enclosing main in SimpleDotCom, you might name your class something like MySimpleTest...

But the point is that a method can't be compiled on its own.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: First question in Beginners forum ...
 
Similar Threads
HeadFirst DotComBust... Help?
Help With With HeadFirst Java Chap.6
return values in methods
HFJ 2nd - Problem with SimpleDotCom
Head First Java- Simple Dot Com Game help