• Post Reply Bookmark Topic Watch Topic
  • New Topic

please help!  RSS feed

 
keith charles
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont understand these compiler error messages:'else' without 'if' eg. else if(Label.equals("Lightgray")). if there are different options eg. if(Label.equals("Yellow"))you cant just have 'if' can you! Also: 'illegal start of expression' eg. public boolean action(Event evt, object arg)how is this illegal! Also: 'cannot resolve symbol' eg. method setMessage(java.lang.String)
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Keith,

As these are basic Java questions, I'm going to move this thread to our "Java in General (Beginner)" forum, and then answer them. See you over there!
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are all basic syntax errors, but the best way to pose the question is not to show us only part of a line (because the error could have been triggered by a mistake in the previous line, or *where* you placed this subexpression). I suggest you post a very short but complete program that demonstrates your error.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

'else' without 'if' eg. else if(Label.equals("Lightgray")). if there are different options eg. if(Label.equals("Yellow"))you cant just have 'if' can you!


You can indeed have just "if" -- the syntax of a chain of if/else statements looks like



There's no "else" before the very first "if". Often the "else without if" message comes from leaving out the braces above that group statements together -- for example, this code would give you that message:




Also: 'illegal start of expression' eg. public boolean action(Event evt, object arg)how is this illegal!


This would be illegal if it appeared in the middle of a method. You might be trying to write this at the top level of a class, but you left out a closing brace at the end of the method just before -- that makes it look as if this line is inside a method, and method declarations can't go inside another method.

Also: 'cannot resolve symbol' eg. method setMessage(java.lang.String)


"Cannot resolve symbol" means that the compiler can't find something by a given name. If you are calling the method above and there's no such method, the compiler will say "can't resolve symbol." If you think the method really does exist, you may be trying to call the method on an instance of the wrong class.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!