Android:我的 if else 语句出现编译错误

发布于 2024-12-08 07:20:37 字数 1977 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓬勃野心 2024-12-15 07:20:37

if 条件末尾有一个分号:

if (item.equalsIgnoreCase("I. The Global Business Environment")); {

结束 if 语句,{ 开始一个新块,然后 else 突然出现。

You have a semicolon at the end of your if conditions:

if (item.equalsIgnoreCase("I. The Global Business Environment")); {

That ends the if statement, the { starts a fresh block, then else shows up out of nowhere.

蓝梦月影 2024-12-15 07:20:37

; 出现在每个 if-else 条件语句中。您最好将它们删除并尝试再次构建它:)

The ; shows up in every if-else condition statement. You're better remove them out and try to Build it again :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文