Java 标记“,”上的语法错误,此标记后应有标识符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21343068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Syntax error on token ",", Identifier expected after this token
提问by user3183409
I'm getting an eclipse error stating:
我收到一个 Eclipse 错误,说明:
Syntax error on token ",", Identifier expected after this token
on the line:
在线上:
@Element(name="Video", =false)
Has anyone encountered this before? I did a google and SO search and I wasn't able to come up with much.
有没有人遇到过这个?我进行了 google 和 SO 搜索,但我无法想出太多。
Source:
来源:
public class Post extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.testparse);
@Element(name="Title",required=false)
String title;
@Element(name="Video", =false)
String video;
}
private void doParse()
{
// static body here, but you can pass a Stream to the serializer too
String xmlBody = "<response><cmd>getPosts</cmd><success>1</success><NumberOfSongs>4</NumberOfSongs><Posts><Post><Title>Stream</Title><Video/></Post><Post><Title>Movies</Title><Video/></Post><Post><Title>Music</Title><Video/></Post><Post><Title>Hello world!</Title><Video/></Post></Posts></response>";
Serializer serializer = new Persister();
PostResponse response = null;
try {
response = serializer.read(PostResponse.class, xmlBody);
} catch (Exception e) {
e.printStackTrace();
}
// something interesting with the classes now
}
}
采纳答案by Federico Piazza
My friend, you have a syntax error missing the key for that value: You are writing:
我的朋友,您有一个语法错误,缺少该值的键:您正在编写:
@Element(name="Video", =false)
and you are missing the "required"
你错过了“必需的”
@Element(name="Title",required=false)