Android:我的 if else 语句出现编译错误
Eclispe 编译器向我显示 else if 上的 else 语句的错误语法。谁能告诉我出了什么问题吗?谢谢!
代码
//click on one of chapters
list.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
String item = ((TextView)view).getText().toString();
Toast.makeText(getBaseContext(), item, Toast.LENGTH_LONG).show();
//Choose Chapter 1
if (item.equalsIgnoreCase("I. The Global Business Environment")); {
//go to chapter 1
startActivity(new Intent(ChaptersActivity.this, Chapter1Activity.class));
} else if (item.equalsIgnoreCase("II. Information Systems")); {
//go to chapter 2
startActivity(new Intent(ChaptersActivity.this, Chapter2Activity.class));
}
//Choose Chapter 3
else if (item.equalsIgnoreCase("III. Operations Management"));
{
//go to chapter 3
startActivity(new Intent(ChaptersActivity.this, Chapter3Activity.class));
}
//Choose Chapter 4
else if (item.equalsIgnoreCase("IV. Marketing"));
{
//go to chapter 4
startActivity(new Intent(ChaptersActivity.this, Chapter4Activity.class));
}
//Choose Chapter 5
else if (item.equalsIgnoreCase("V. Managing Human Capital"));
{
//go to chapter 5
startActivity(new Intent(ChaptersActivity.this, Chapter5Activity.class));
}
//Choose Chapter 6
else if (item.equalsIgnoreCase("VI. Preparing for the Examination"));
{
//go to chapter 6
startActivity(new Intent(ChaptersActivity.this, Chapter6Activity.class));
}
}
});
他们在“其他”代码单词上显示错误语法,有什么想法吗?
The Eclispe complier show me the error sntax on my else statements on my else if. Can anyone tell me what's wrong? thanks!
code
//click on one of chapters
list.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
String item = ((TextView)view).getText().toString();
Toast.makeText(getBaseContext(), item, Toast.LENGTH_LONG).show();
//Choose Chapter 1
if (item.equalsIgnoreCase("I. The Global Business Environment")); {
//go to chapter 1
startActivity(new Intent(ChaptersActivity.this, Chapter1Activity.class));
} else if (item.equalsIgnoreCase("II. Information Systems")); {
//go to chapter 2
startActivity(new Intent(ChaptersActivity.this, Chapter2Activity.class));
}
//Choose Chapter 3
else if (item.equalsIgnoreCase("III. Operations Management"));
{
//go to chapter 3
startActivity(new Intent(ChaptersActivity.this, Chapter3Activity.class));
}
//Choose Chapter 4
else if (item.equalsIgnoreCase("IV. Marketing"));
{
//go to chapter 4
startActivity(new Intent(ChaptersActivity.this, Chapter4Activity.class));
}
//Choose Chapter 5
else if (item.equalsIgnoreCase("V. Managing Human Capital"));
{
//go to chapter 5
startActivity(new Intent(ChaptersActivity.this, Chapter5Activity.class));
}
//Choose Chapter 6
else if (item.equalsIgnoreCase("VI. Preparing for the Examination"));
{
//go to chapter 6
startActivity(new Intent(ChaptersActivity.this, Chapter6Activity.class));
}
}
});
They display error sntax on 'else' codes words, any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
if 条件末尾有一个分号:
结束 if 语句,{ 开始一个新块,然后 else 突然出现。
You have a
semicolon
at the end of your if conditions:That ends the if statement, the { starts a fresh block, then else shows up out of nowhere.
;
出现在每个if-else
条件语句中。您最好将它们删除并尝试再次构建它:)The
;
shows up in everyif-else
condition statement. You're better remove them out and try to Build it again :)