• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What am I doing wrong... This code won't complie, and I don't know why

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was attempting to write and complie the example code found here I keep reciving the following error: "SpotRunTo.java:5: ';' exspected".

I'm guessing that the compiler is telling me that on line 5 it's exspecting a ';' ?

Here's a copy of the code I'm trying to compile:

public class SpotRunTo
{

public static void main( Strings[] args )

if (args.length == 0 )
{
System.out.println( "Spot is now home" );
}
else
{
System.out.println( "Spot is now in " + args[0] );
}
}



What am I missing? I've gone through this many times and I'm lost. I don't see what I'm missing. Thanks in advance for pointing me in the right direction.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jesse Wilson:
... What am I missing? ...


Welcome to JavaRanch!

You are missing 2 braces, and you have an 's' at the end of String.
 
Jesse Wilson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a bunch! I was able to finally complie the code! WOO HOOO!!

On a side note: The error message I was reciving at the command line... What was it trying to tell me? I have no idea how I was to decipher that I needed to add braces from the message that the computer spit out.

Thanks again!!
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when you're missing braces, things go all kinds of wonky. teh compiler TRIES to figure out what you're doing, but it's usually wrong.

i think that since you didn't have your opening brace in your main method... well... i don't know what it was thinking.

whenever you see that "missing ;" message, if the reported line HAS a semi-colon, look at the few lines above the reported one for anything strange/missing. like a '{' or '}'.
 
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic