Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: "Syntax error on token ";", , expected" Why?

I am going crazy now. Googled this, thought some kind of IDE bug. Maybe I am blind and can not see something...but this was OK just an hour ago. I commented out all of the code and still it won't compile.

public class CityExplorerPoi extends Activity {

private POI displayedPOI = null;
private MediaPlayer mPlayer;
enum audioState {
    Idle,               //Idle, not initialized
    Initialized,        //Initialized, not prepared
    Prepared,           //Prepared
    Started,            //Playing
    Stopped,            //needs preparing
    Paused,             //can be Started or Stopped
    Preparing,          //...
    End,                //Released, useless
    Error,              //...
    PlaybackCompleted   //can be Started from beginning or Stopped
};
audioState aState; <<<<<<<<<<ERROR

mPlayer = new MediaPlayer();
}

This code has a compilier error on line marked with ERROR saying Syntax error on token ";", , expected

With enum declaration I tried to go without ; after }. Tried to put ; after the last entry (PlaybackCompleted) and still nothing???

Any ideas? What am I missing :(

like image 718
Dusko Avatar asked Mar 30 '12 11:03

Dusko


2 Answers

This is the actual problem:

mPlayer = new MediaPlayer();

That's just a statement - but it's not in a constructor, method or other initializer. It's not clear why you don't just assign a value at the point of the declaration:

private MediaPlayer mPlayer = new MediaPlayer();

I'd also recommend removing the redundant semi-colon at the end of the enum declaration.

like image 119
Jon Skeet Avatar answered Nov 16 '22 00:11

Jon Skeet


It's not an IDE bug.

You have a semicolon after the closing } of the enum. That is not required.

You've also got mPlayer = new MediaPlayer(); floating in your code, outside a method.

I'd suggest reading a good book on Java, like this one: http://www.amazon.co.uk/Agile-Java-Crafting-Test-Driven-Development/dp/0131482394

And a good book on Android: http://www.amazon.co.uk/Android-Application-Development-Dummies-Computers/dp/047077018X/ref=sr_1_1?s=books&ie=UTF8&qid=1333106527&sr=1-1

like image 28
Ollie C Avatar answered Nov 15 '22 23:11

Ollie C