Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

First question in Beginners forum ...  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

 
Tonya Cash
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Marc! I see exactly what you mean ...
-Tonya
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!