我看到了奇怪的情况:在我的 Android 应用程序代码中使用类似这样的东西时我没有收到任何错误:
@Override
public void onBackPressed() {
if (getActionBar().getSelectedTab().getPosition()==1)**;**
{
if ( getFragmentManager().findFragmentByTag("Tag B") instanceof ContactsArchiveFragment)
{
final ContactsArchiveFragment fragment = (ContactsArchiveFragment) getFragmentManager().findFragmentByTag("Tag B");
if (fragment.allowBackPressed()) { // and then you define a method allowBackPressed with the logic to allow back pressed or not
Log.i("calls act back cont archive", "on back clicked");
super.onBackPressed();
}
}
}
}
当我尝试做这样的事情时:
@Override
public void onBackPressed() {
if (getActionBar().getSelectedTab().getPosition()==1);
{
if ( getFragmentManager().findFragmentByTag("Tag B") instanceof ContactsArchiveFragment)
{
final ContactsArchiveFragment fragment = (ContactsArchiveFragment) getFragmentManager().findFragmentByTag("Tag B");
if (fragment.allowBackPressed()) { // and then you define a method allowBackPressed with the logic to allow back pressed or not
Log.i("calls act back cont archive", "on back clicked");
super.onBackPressed();
}
}
}
else
{
}
}
我收到了Syntax error on token "else", delete this token
。当我看到半成品时,我意识到问题出在哪里。但这让我很奇怪,有人可以解释它是什么吗?