错误:“令牌上的语法错误”;“,预期的”为什么? [英] ERROR: "Syntax error on token ";", , expected" Why?

查看:813
本文介绍了错误:“令牌上的语法错误”;“,预期的”为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在很疯狂Googled这个,想到一些IDE错误。也许我是盲目的,看不到什么...但是这只是一个小时前。我注释掉了所有的代码,仍然不会编译。

  public class CityExplorerPoi extends Activity {

私人POI显示POI = null;
私人MediaPlayer mPlayer;
枚举audioState {
空闲,//空闲,未初始化
初始化,//初始化,未准备
准备好,//准备
开始,//播放
停止,//需要准备
暂停,//可以启动或停止
准备,// ...
结束,//发布,无用
错误, // ...
PlaybackCompleted //可以从开始或停止
};
audioState aState; <<<<<<<< ERROR

mPlayer = new MediaPlayer();
}

此代码在标有ERROR的行上有一个比较复杂的错误,说语法令牌错误;,,预期



使用枚举声明我试图没有;之后}。试过了在最后一个条目之后(PlaybackCompleted),仍然没有?



任何想法?我缺少什么:(

解决方案

这是实际的问题:

  mPlayer = new MediaPlayer(); 

声明 - 但它不是在构造函数,方法或其他初始化程序中。不清楚为什么您不仅仅是在声明点分配一个值:

  private MediaPlayer mPlayer = new MediaPlayer(); 

我还建议在枚举声明结尾处删除多余的分号。


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

解决方案

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.

这篇关于错误:“令牌上的语法错误”;“,预期的”为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆