Syntax error on token goto throw expected
Possible Duplicate:
Is there a goto statement in java?
在我的Android应用程序中,我使用goto语句来控制流。但我收到的错误是"token goto语法错误,需要throw"。这是我的密码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | label: if(alc) { r_code=st.nextToken(); AlertDialog.Builder alert=new AlertDialog.Builder(Fetch.this); alert.setTitle(count+" records found for"+rytname.getText().toString()); alert.setMessage("Are you sure want to search for"+r_code+"?"); alert.setPositiveButton("YES", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ff=1; alc=false; } }); alert.setNegativeButton("NO", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub ff=0; } }); alert.show(); if (ff==0) { goto label; } |
我是这个Android的新手,帮助我避免这个错误
型
在Java中没有工作EDOCX1 0
即使Java关键字列表指定GOTO关键字,它也被标记为未使用。因此,它不能工作。您必须在不使用
一般提示:有标记的语句
Statements may have label prefixes.
1
2
3
4
5 LabeledStatement:
Identifier : Statement
LabeledStatementNoShortIf:
Identifier : StatementNoShortIfThe Identifier is declared to be the label of the immediately contained Statement.
Unlike C and C++, the Java programming language has no goto statement;
identifier statement labels are used with break (§14.15) or continue
(§14.16) statements appearing anywhere within the labeled statement.The scope of a label of a labeled statement is the immediately
contained Statement. – JLS (§14.7)
号
但您真正想要的是在不使用它的情况下重写您的构造,例如使用
1 2 3 | while (f == 0) { // ... } |
型
而不是:
1 2 3 4 5 6 | label: ...// the rest of your code if (ff == 0) { goto label; } |
号
使用此:
1 2 3 | do { ...// the rest of your code while (ff == 0); |
如果可以将其转换为:
1 2 3 | while (ff == 0) { ...// the rest of your code } |
。
型
不建议在代码中使用