我现在疯了。谷歌搜索这个,想到了某种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();
}
此代码在标有ERROR的行上有一个更严重的错误,说明令牌上的语法错误“;”,预期
随着enum声明我试图没有;之后}。试图把;在最后一个条目(PlaybackCompleted)之后仍然没有???
有什么想法吗?我错过了什么:(
答案 0 :(得分:16)
这是实际问题:
mPlayer = new MediaPlayer();
这只是一个声明 - 但它不在构造函数,方法或其他初始化器中。目前尚不清楚为什么你不只是在声明点分配一个值:
private MediaPlayer mPlayer = new MediaPlayer();
我还建议在枚举声明的末尾删除多余的分号。
答案 1 :(得分:4)
这不是IDE的错误。
枚举结束后你有一个分号。这不是必需的。
在方法之外,您的代码中还有mPlayer = new MediaPlayer();
个浮动。
我建议你阅读一本关于Java的好书,就像这样: http://www.amazon.co.uk/Agile-Java-Crafting-Test-Driven-Development/dp/0131482394
一本关于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
答案 2 :(得分: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();
}