2012-03-30 109 views
6

我現在瘋了。谷歌搜索這個,認爲某種IDE錯誤。也許我是盲人,看不到什麼......但是就在一個小時前,這就好了。我註釋掉了所有的代碼,但仍然無法編譯。錯誤:「令牌上的語法錯誤」;「,,預計」爲什麼?

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(); 
} 

此代碼對標有錯誤,指出令牌語法錯誤線compilier錯誤「;」,預計

隨着枚舉聲明我試圖去無;後}。試圖把;最後一個條目(PlaybackCompleted)後,仍然沒有什麼?

任何想法?我在想什麼:(

+0

您是否試圖清理您的項目? – eightx2 2012-03-30 11:21:45

回答

16

這是實際的問題:

mPlayer = new MediaPlayer(); 

這只是一個說法 - 但它不是在構造函數,方法或其他初始化目前尚不清楚爲什麼你不只是在聲明中對分配一個值:

private MediaPlayer mPlayer = new MediaPlayer(); 

我也建議在枚舉聲明的末尾刪除多餘的分號

+0

D'oh :(我知道,但我很盲目,謝謝! – Dusko 2012-03-30 11:34:04

1

的問題是在這裏。

mPlayer = new MediaPlayer(); 

您可以在聲明點處指定值。 就是這樣。

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(); 
} 
相關問題