1. Are you ready for the Galaxy S20? Here is everything we know so far!

Change Activity via Options Menu

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

  1. gorjan

    gorjan Lurker
    Thread Starter

    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.
     



    1. Download the Forums for Android™ app!


      Download

       
  2. sscAndroid

    sscAndroid Newbie

    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.
     
Loading...
Similar Threads - Change Activity via
  1. No name from the internet
    Replies:
    4
    Views:
    237
  2. HotspotSwitchIp
    Replies:
    1
    Views:
    524
  3. dj_nick_t
    Replies:
    2
    Views:
    494
  4. Biffos
    Replies:
    10
    Views:
    592
  5. writerman
    Replies:
    3
    Views:
    664
  6. stuarta
    Replies:
    3
    Views:
    495
  7. Sunny Rio
    Replies:
    18
    Views:
    927
  8. Alex Ethridge
    Replies:
    9
    Views:
    850
  9. RedHeadDev
    Replies:
    4
    Views:
    950
  10. Kuldip Somwanshi
    Replies:
    0
    Views:
    2,098

Share This Page

Loading...