无法访问的代码android

时间:2013-01-03 20:03:24

标签: android

我整天都在编程,现在回来后我无法接触;在

return;
Recipe093.path[1] = localCursor.getString(1);

如果我删除了返回,我会在继续后获得无法访问的代码; 为什么我的代码无法访问? 希望有人可以帮助我,谢谢。 这是我的代码:

public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(R.layout.musiclist);
    final Cursor localCursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, (String[])null, null, (String[])null, null);
    String[] arrayOfString1 = localCursor.getColumnNames();
    int i = arrayOfString1.length;
    for (int j = 0; ; j++)
    {
      if (j >= i)
      {
        String[] arrayOfString2 = { "title", "artist", "duration" };
        int[] arrayOfInt = { 2131099668, 2131099669, 2131099670 };
        SimpleCursorAdapter localSimpleCursorAdapter = new SimpleCursorAdapter(getApplicationContext(), 2130903044, localCursor, arrayOfString2, arrayOfInt);
        localSimpleCursorAdapter.setViewBinder(new AudioListViewBinder());
        ListView localListView = (ListView)findViewById(2131099667);
        localListView.setAdapter(localSimpleCursorAdapter);
        Log.d("test", "start list()");
        localListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
        {
          public void onItemClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
          {
            switch (Recipe093.this.getIntent().getIntExtra("case1", 0))
            {
            default:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            }
            while (true)
            {
              Intent localIntent = new Intent(Recipe093.this.getApplicationContext(), MainActivity.class);
              Recipe093.this.startActivity(localIntent);
              return;
              Recipe093.path[1] = localCursor.getString(1);
              SharedPreferences.Editor localEditor10 = Recipe093.this.getSharedPreferences("FileName", 3).edit();
              localEditor10.putString("userChoice", Recipe093.path[1]);
              localEditor10.commit();
              continue;
              Recipe093.path[2] = localCursor.getString(1);
              SharedPreferences.Editor localEditor9 = Recipe093.this.getSharedPreferences("FileName", 3).edit();
              localEditor9.putString("userChoice1", Recipe093.path[2]);
              localEditor9.commit();
            } 
          }
        });
        return;
      }
      Log.d("Recipe093", arrayOfString1[j]);
    }
  }

  private class AudioListViewBinder
    implements SimpleCursorAdapter.ViewBinder
  {
    private AudioListViewBinder()
    {
    }

    public boolean setViewValue(View paramView, Cursor paramCursor, int paramInt) {
        // TODO Auto-generated method stub
          int i = paramCursor.getColumnIndex("title");
          int j = paramCursor.getColumnIndex("artist");
          int k = paramCursor.getColumnIndex("duration");
          if ((paramInt == i) || (paramInt == j))
            ((TextView)paramView).setText(paramCursor.getString(paramInt));
        return false;
    }

  }
  }

2 个答案:

答案 0 :(得分:6)

基本上,return;表示“立即退出此方法”。因此,在返回语句之后的任何内容都不会运行。

您可以使用范围来获得多个回报:

if(x == 1) {
    return;
    // Nothing will be called here on down in this scope, i.e. before `}`
}
x = 1;
return; 
// Nothing will be called here on down

答案 1 :(得分:1)

如果可以return;代码停止并返回第一个方法。它不会在此行之后运行任何代码。与break;

相同的故事