Follow the instructions on the error and go to your
C:\Users\directory\.android\avd/Nexus_5_API_24.avd/*.lock
and delete all files with the .lock extension and it should work.
There are so many answer but i just extending to give answer of this question. What happen is when i follow Android Studio instruction and try to delete that folder Or file but i am not able to delete it, So what am i do is that i open the AVD Manager and click on down arrow which is on right side as you can see in below screenshot and click on stop after click on start and its working fine. There is no need to restart or recreate the AVD.
When you go to the specified location and try to delete those files sometimes you might get an error stating that the file or folder is already open or is used by another application
So the simple Solution is just to go to
Tools > Android > AVD Manager and Stop the AVD that you are trying to run
Then When you try to run the AVD again you might have the problem resolved
In your Android Studio go to Tools->Android->AVD Manager. It will list your virtual devices. Click the Action column corresponding to your virtual device. It will list many actions. Click on Stop. This will shutdown your android studio. Now start android studio. Your virtual device should work fine.
Open Terminal, cd to the given path. List all the files using the command ls. You will see two files with .lock extensions or maybe more. Just delete those files.
I closed the emulator, clicked the AVD Manager Icon on the menubar then under the emulators actions tab downward arrow I selected "Cold Boot Now" then ran the program normally by pressing SHIFT + F10
I'm don't know if some one is still having this problem, but, in my case, it's was an issue related to VAGRANT.... more precisely whit Virtual Box.
I just stop the vBox proccess (i'm ussing ubuntu), remove the .lock files related to the emulator inself and that's it... the emulator should by ready to go.
Go to the down arrow and click on the "Show on Disk" link like attached image. You will get the list of all files, remove the file "hardware-qemu.ini.lock" and start again.
I Also have the same problem but in ubuntu 20.04 and I had to navigate to /home/your_username/.android/avd/Pixel_2_API_28.avd/*.lock and then delete all file with .lock
Note: you first need to enable show hidden files and I may have used different device (Pixel_2_API_28) from yours but it is applied to any device