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

87,813

Solution 1

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.

Solution 2

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

Solution 3

The problem is here.

mPlayer = new MediaPlayer();

You assign the value at the point of declaration. Just like this.

public class CityExplorerPoi extends Activity {

    private POI displayedPOI = null;

    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;
    MediaPlayer mPlayer = new MediaPlayer();
}
Share:
87,813
Dusko
Author by

Dusko

@Duskox

Updated on December 05, 2020

Comments

  • Dusko
    Dusko over 3 years

    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 :(