Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Jesse Wilson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • 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
  • 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!!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • 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 '}'.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!