ERROR: “Syntax error on token ”;“, , expected” Why?

前端 未结 3 768
隐瞒了意图╮
隐瞒了意图╮ 2021-01-05 09:38

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 c

相关标签:
3条回答
  • 2021-01-05 10:07

    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

    0 讨论(0)
  • 2021-01-05 10:09

    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.

    0 讨论(0)
  • 2021-01-05 10:24

    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();
    }
    
    0 讨论(0)
提交回复
热议问题