循环中无法访问的代码

时间:2012-04-13 17:59:28

标签: java android loops

我相对来说是一个noobie,并一直在搜索和试图找出我的代码有什么问题。这是一个基本的列表视图,将被分解为子列表的

   ListView localListView = (ListView)findViewById(2131361899);
    localListView.setAdapter(new ArrayAdapter(this, 2130903117, arrayOfString));
    localListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
//Start//
      public void onItemClick(AdapterView<?> paramAdapterView, View paramView, int paramInt, long paramLong)
      {
        String str = ((TextView)paramView).getText().toString();
        if (str.equalsIgnoreCase(ChapterList.this.getResources().getString(2131230721)))
          ChapterList.this.startActivity(new Intent(ChapterList.this, Foreword.class));
        while (true)
        {return;
        //The Error starts here//
        if (str.equalsIgnoreCase(ChapterList.this.getResources().getString(2131230723)))
        {
          ChapterList.this.startActivity(new Intent(ChapterList.this, Chapter1Section.class));
          continue;
        }
          //And ends here//
        if (str.equalsIgnoreCase(ChapterList.this.getResources().getString(2131230728)))
        {
          ChapterList.this.startActivity(new Intent(ChapterList.this, Chapter2Section.class));
          continue;
        }
        if (str.equalsIgnoreCase(ChapterList.this.getResources().getString(2131230745)))
        {
          ChapterList.this.startActivity(new Intent(ChapterList.this, Chapter3Section.class));
          continue;
        }
        if (str.equalsIgnoreCase(ChapterList.this.getResources().getString(2131230752)))
        {
          ChapterList.this.startActivity(new Intent(ChapterList.this, Chapter4Section.class));
          continue;
        }
        if (str.equalsIgnoreCase(ChapterList.this.getResources().getString(2131230759)))
        {
          ChapterList.this.startActivity(new Intent(ChapterList.this, Chapter5Section.class));
          continue;
        }
        if (str.equalsIgnoreCase(ChapterList.this.getResources().getString(2131230764)))
        {
          ChapterList.this.startActivity(new Intent(ChapterList.this, Chapter6Section.class));
          continue;
        }
        if (str.equalsIgnoreCase(ChapterList.this.getResources().getString(2131230765)))
        {
          ChapterList.this.startActivity(new Intent(ChapterList.this, Chapter7Section.class));
          continue;
        }
        if (str.equalsIgnoreCase(ChapterList.this.getResources().getString(2131230768)))
        {
          ChapterList.this.startActivity(new Intent(ChapterList.this, Chapter8Section.class));
          continue;
        }
        if (str.equalsIgnoreCase(ChapterList.this.getResources().getString(2131230778)))
        {
          ChapterList.this.startActivity(new Intent(ChapterList.this, Chapter9Section.class));
          continue;
        }
        if (!str.equalsIgnoreCase(ChapterList.this.getResources().getString(2131230722)))
          continue;
        ChapterList.this.startActivity(new Intent(ChapterList.this, Appendix.class));
        }
      }

1 个答案:

答案 0 :(得分:1)

将无法访问return;语句后面的代码。 在while循环块内部,每次评估一个语句。 但是,当评估return;语句时,整个方法“返回”对调用方法的控制,并且不再在该方法中执行代码。