'android studio. Error: The file name must end with .xml

I am trying to add icons on the action bar of my app, so I have imported an icon(.png) in the drawable folder but there is an error saying that the file name must end with .xml

The following is my xml code:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity">

    <item android:id="@+id/action_create_order"
        android:title="@string/action_create_order"
        android:icon="@drawable/ic_action_name"
        android:orderInCategory="1"
        app:showAsAction="always">
    </item>

    <item android:id="@+id/action_settings"
        android:title="@string/action_settings"
        android:orderInCategory="100"
        app:showAsAction="never" />
</menu>

The error is coming for the first item(ic_action_name).



Solution 1:[1]

You need use vector instead image on drawble folder

Try the sample as follow on your drawable/ic_menu_camera.xml:

ic_menu_camera.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportHeight="24.0"
    android:viewportWidth="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0" />
    <path
        android:fillColor="#FF000000"
        android:pathData="M9,2L7.17,4H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2H9zm3,15c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z" />
</vector>

Solution 2:[2]

You can do two things for the error.

  1. Check the place where it is showing error and see if you have any files which does not have .xml as extension and then press Shift+F6 (on Windows) to rename and add .xml

  2. If you don't see any files not having .xml extension then just go to File -> Invalidate Caches and Restart

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abner Escócio
Solution 2 oyeraghib