0
<?xml version="1.0" encoding="utf-8"?>
<menu 
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/action_shuffle"
        android:icon="@drawable/rand"
        android:orderInCategory="1"
        android:showAction="always"
        android:title="shuffle"/>
    <item
        android:id="@+id/action_end"
        android:icon="@drawable/end"
        android:orderInCategory="2"
        android:showAction="always"
        android:title="End"/> 
</menu>

@Override
    public boolean onOptionsItemSelected(MenuItem item){
        switch (item.getItemId()){
            case R.id.action_shuffle:
                //shuffle
                 break;
             case R.id.action_end:
                 stopService(playIntent);
                 musicSrv=null;
                 System.exit(0);
                 break;
         }
         return super.onOptionsItemSelected(item);
     }

I am having sleepless night on this matter. I have tried all I could but this is giving me real time headache.

At first it was uri not registered error but after I validated the error now read thus:

Error:External resource http://schemas.android.com/apk/res/android is not registered.

How do I register this?

Error #2

Error:(2, 66) cvc-elt.1.a:cannot find the declaration of element of 'menu'

Error: Premature end of file

Matthieu Meunier
  • 458
  • 5
  • 21
Ajiroghene
  • 127
  • 1
  • 9

1 Answers1

5

Menu must be in menu resource folder.
Check the steps below this code.

remove the below line from menu file, its not required :

<?xml version="1.0" encoding="utf-8"?>

see i have edited your menu file code below :

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/action_shuffle"
        android:icon="@drawable/rand"
        android:orderInCategory="1"
        app:showAction="always"
        android:title="shuffle"/>
    <item
        android:id="@+id/action_end"
        android:icon="@drawable/end"
        android:orderInCategory="2"
        app:showAction="always"
        android:title="End"/>
</menu>

Edit :

After seeing your code, i found mistake you have done. You created menu file in wrong folder. you need create menu file in res directory. I am giving you steps for creating menu file.

Note : delete your menu file or save in your computer before going this steps. remember menu file name should not be menu, because same name file or folder you cant create in android studio

Steps:

  1. Right click on res directory

  2. click on new

  3. click on Android Resource directory

  4. select menu in Resource type

  5. click on ok

  6. now copy paste your menu file in menu directory or you can go to next steps for creating new menu file like below :

Steps for creating menu file :

  1. Right click on menu directory

  2. click on new

  3. select menu resource file

  4. enter the name of menu file you want to create eg. "dashboard_menu"

  5. now add your code you want to add in menu file

sifr_dot_in
  • 3,153
  • 2
  • 33
  • 42
Hitesh Sarsava
  • 666
  • 4
  • 15