1. Download our Official Android App: Forums for Android!

Apps Change Activity via Options Menu

Discussion in 'Android Development' started by gorjan, Oct 27, 2010.

  1. gorjan

    gorjan Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    3
    Joined:
    Oct 27, 2010

    Oct 27, 2010
    3
    0
    25
    Hi All,

    I'm really new to Android development, so I have one basic question.
    I have the following code. I want to change the screen(the Activity) via Options menu:
    Code (Text):
    1.  
    2.  
    3. @Override
    4.     public boolean onOptionsItemSelected(MenuItem item) {
    5.         // TODO Auto-generated method stub
    6.         switch (item.getItemId())
    7.         {
    8.         case R.id.item01:
    9.             Intent intentItem1 = new Intent(this, Item1Activity.class);
    10.             startActivityForResult(intentItem1, 0);
    11.             //startActivity(intentItem1);
    12.             return true;
    13.            
    14.         default: return super.onOptionsItemSelected(item);
    15.         }
    16.        
    17.     }
    18.  
    But the activity doesn't change and the error message I receive while debugging is that "The resource doesn't exist"

    Any ideas?

    Thanks in advance.
     

    Advertisement

  2. sscAndroid

    sscAndroid Newbie
    Rank:
    None
    Points:
    16
    Posts:
    17
    Joined:
    Oct 23, 2010

    Oct 23, 2010
    17
    1
    16
    Your code for changing the activity looks solid.

    If you receive the error that a resource cannot be found, that means you're accessing a xml resource that just isn't there. In your example, the only line where you access a resource is your
    Code (Text):
    1.  
    2. case R.id.item01:
    3.  
    line. You should check if your menuitem is really spelled that way.

    Besides, your compiler should tell you exactly where and what is causing the error, just check the logcat output.
     

Share This Page

Loading...