39

For some unknown reason, I can't edit files in Android Studio. This includes both Java and XML files.

When I launch Android Studio (v1.2.2), everything is fine. However, after some time, I lose the ability to edit files content. Here is what I noticed:

  • When I click on any line in the source code, the lines get highlighted but the caret indicator is not showing.
  • When I start typing, a search for: box starts appearing on the top of the left panel (Project window), and it starts filtering the project files according to what I type!
  • Files are not locked as Read-Only. I checked.
  • Restarting Android Studio did not resolve it permanently. Everything seems fine for some time, then the problem appears again.
  • I did check my keyboard to see if I have a stucked keystroke that might cause this problem. Didn't notice anything.
  • In the Project window, I noticed that MainActivity file name is in grey (See the screenshot below). I'm not sure if this is because of something I did, or if it is how Android Studio identifies the main Activity in the project.

Project View Screenshot

3
  • which source control are you using ?
    – danysz
    Jul 29, 2015 at 11:00
  • @danysz IF you mean 'version control', then I'm not using it at all. I never did use it with Android Studio.
    – iTurki
    Jul 29, 2015 at 11:05
  • This is the only thing that worked for me on Ubuntu 20.04. stackoverflow.com/a/67470744/4437468 May 10, 2021 at 12:52

27 Answers 27

77

This appears to be that the Code view loses focus to the Project view. That's why I can't edit the code and the search box appears: because The focus is with the Project view, permanently.

I couldn't find a permanent solution. However, by accident, I found a workaround that is less annoying than restarting Android Studio:

When you lose focus to the Project view, click on the far right of the Code View, where the scrollbar exist.

I tried to figure out what causes the Project View to steal the focus permanently but I couldn't. Until someone do, this will be the accepted answer.

9
  • which OS are you using ?
    – danysz
    Jul 29, 2015 at 21:28
  • @danysz Windows 7 (64-bit)
    – iTurki
    Jul 30, 2015 at 5:48
  • Meet the same issue on OSX, it works perfect! Before I see this answer ,every time I restart the computer.Thanks a lot
    – Ninja
    Jan 11, 2016 at 3:14
  • clicking on the scroll view helps, but when your activities have ~2k LoC like mine and you are using split view for switchting between 2 activities, it becomes very annoying to always click on the scrollbar, which will let you show a different excerpt of your activity and you will have to scroll up/down to find the piece you've been working on. I need a permanent solution.
    – MojioMS
    Apr 23, 2016 at 23:50
  • 1
    @mojioMS 2K LoC definitely sounds like a code smell... Your activities are trying to do way too much.
    – Justin
    Oct 15, 2016 at 4:03
17

click on vertical scroll bar area to get focus in project view

click on vertical scroll bar area to get focus in project view

15

I have faced same problem and tried some of the solutions above. None of worked for me. After File -> Invalidate Caches/Restart the problem have been solved.

1
  • 1
    After a system crash (Win7) I loosed my editor view. 'Invalidate Caches & Restart' woks for me. Thank you!
    – Tof
    Apr 3, 2019 at 7:36
8

This problem may be related with time of your computer. I faced this issue and realized that when i fix my computer time and restart android studio (also php storm) it fixes problem completely. Still my laptop has a time problem (cause of CMOS battery) and sometimes i forgot to change time of my computer before open the Android Studio, can not focus anywhere correctly. If i fix time of my computer and restart editors. it fixes. As i understand there are various causes of this cant focus problem. I write this answer because non of these answers (on stackoverflow) could solve my problem.

2
  • 1
    fixed my problem on android studio 3.1rc5 / ubuntu! i had changed the date/time to extend a product trial which was recently expired. wouldnt have thought this could cause random focus issues
    – jcuypers
    Jan 20, 2018 at 15:22
  • 1
    In windows 10 turning on "Set time automatically" solved my problem
    – farhang67
    Sep 26, 2018 at 9:22
4

Permanent Fix for Can't Edit Files in Android Studio On Windows. Performing the following steps:

  1. Close Android studio.
  2. Go to your User Folder - on Windows 7/8 this would be:

[SYSDRIVE]:\Users[your username] (ex. C:\Users\Venky)

In this folder there should be a folder called .AndroidStudioBeta or .AndroidStudio (notice the period at the start - so on some OSes it would be hidden).

  1. Delete this folder (or better yet, move it to a backup location - so you can return it if something goes wrong).

This should reset your Android Studio settings to default.

  1. Now the isue got fixed, check it by opening Android studio.

This will not clear any projects history.

3

tl;dr, open the search with cmd + shift + f and close it again. All should be good.


I was also having the problem of suddenly losing the ability to type in the editor on my mac. There was never any rhyme or reason. I tried the suggestions here and sadly they didn't work.

What worked for me is opening the search box with cmd + shift + f (on mac). Once that opened and I closed it, I could type again. I also noticed the things I had been trying to type were in the search bar.

2

TL;DR: to fix it on OSX run in the terminal:

defaults write -g ApplePressAndHoldEnabled -bool false 

Details: I had this issue for years on OSX in Android Studio and in all the other Intellij Based apps (AppCode, WebStorm, IntelliJ Idea, etc): after some time the editor loses focus and it's not possible to edit anymore until switch to another window or clicking on a status bar. Usually it happens couple of times per day and although I'm a big fan of IntelliJ stack it was very annoying. That's why I decided to provide a detailed explanation how to get rid of this problem and hope my fix might help someone since I can't find a definitive solution around.

As I found on the net potential solution is to use Oracle JDK as an IDE boot JDK but it has problems with fonts and not acceptable in my case.

Using instructions in https://intellij-support.jetbrains.com/hc/articles/206544879 I've tried to work-around this problem with the latest IntelliJ JDK (112 b801) from: https://bintray.com/jetbrains/intellij-jdk/download_file?file_path=jbsdk8u112b801_osx_x64.tar.gz

To set it up just use Help > Find Action...

enter image description here

and select the JDK downloaded from the above mentioned location

enter image description here

I had the feeling that issue became less frequent but it still took place at least once per day.

After some time the link mentioned below inspired me to try to experiment with the system OSX setting which blocks keyboard input after press and hold a single key. Many thanks to Jonathan Ruckwood's observation here:

https://youtrack.jetbrains.com/issue/IDEA-152818#comment=27-1434006

By default OSX prevents keys repeat after press and hold (see details here: https://discussions.apple.com/thread/5038771?tstart=0). You can easily see it in any text editor (except Emacs, terminal and maybe some others) when press any letter key it won't produce several characters in contrary to arrow keys and some other keys which can be repeated. This behaviour can be changed. I was thinking about some potential interference during keyboard blocking between the system and IntelliJ IDE and tried the following command to prevent key repeat block (it could be changed back to true at any time):

defaults write -g ApplePressAndHoldEnabled -bool false 

After applying this command the Android Studio or other IntelliJ IDE should be restarted. Before I had such keyboard blocking errors several times per day and now after 3 days there is no any sign of this nuisance. Fingers crossed... In any case I think it's better now than before. One additional configuration change I did is using custom boot JDK (it did not work alone but maybe it works together with ApplePressAndHoldEnabled parameter).

Having that said I believe it's a bug and must be fixed to work on OSX out of the box without modifying default settings and boot JDKs. This way please vote for the fix here:

https://youtrack.jetbrains.com/issue/IDEA-152818#comment=27-1434006

3
  • 1
    This is exactly what happened to me. Brilliant!
    – Jose Jet
    Mar 26, 2019 at 9:40
  • 1
    This is the answer. Who would have thought the "key hold and press" setting was the answer?
    – dhaag23
    Nov 25, 2020 at 22:16
  • Right, it was the last thing I thought of ;) Nov 26, 2020 at 1:21
2

Just Turn off/Disable the "IdeaVim" extension.

1

This's because of ideaVim for my case. And you can switch from this mode (uneditable) by clicking "i" on your keyboard.

To get more information about ideaVim : https://www.jetbrains.com/help/pycharm/using-product-as-the-vim-editor.html#vimrc

0

i was facing same problem in macox. i was installed some randomly plugins which cause this error. so after removing vim editor(in my case) it works fine.

0

I had this problem as well, but it was because my focus was in an EditText view in the emulator. I could not get it to work by clicking the right scroll bar. It was only when I noticed the cursor n the emulator, and hit tab, did my editor work again.

0

I was also having this problem and had tried to delete the configuration files and reinstall the Android Studio, but the problems were still there. Then I found out that if I uncheck the "vim emulator" under tool, the problem goes away!

0

your file system maybe in read only

move your project to another folder or drive

enter image description here

0

i was facing same problem in project. i was change the time of my computer which cause this error. so after invalidate caches and restart studio , it works fine.

0

I had this issue appear after using external displays via USB DisplayLink for some time. After disconnecting USB and reconnecting everything returns to normal but the issue may still appear after a few days, this is just a temporary fix.

0

In case above clicking scroll bar workaround doesn't work:

Use mouse(not keyboard shortcut) to do a copy/parse via right-click menu, the edit will be back.

0

The only solution that worked with me:

  1. Close Android Studio.
  2. Save .idea folder for future restore (if something happened).
  3. Remove .idea folder (or just rename it).
  4. Start Android Studio and open project.
0

1- Close Android Studio.

2 - Remove .idea folder from your project

3 - Start Android Studio and open project.

0
0

uninstall IdeaVIM solved my problem. Android studio> Preferences > Plugins > IdeaVim (uninstall)

0

short and clear, disable Vim plugin. On Windows, just go to settings / plugins then find vim and disable and restart your IDE.

On mac do the same, but start on Preferences then choose plugins.

0

After going through all the above recommendations and trying different things, most of which didn't work for me. I came to realize that all I needed to do was press the key "i" on my keyboard and it became normal.

I am using a MacBook Pro, it might be different on Windows, but that was what worked for me.

I wish you all the best.

0

I had a similar problem and clicked in the bottom right corner on a V which is coloured green, a small screen comes up to say IdeaVim is enabled, untick this and hey presto! typing is back to normal.

0

Just changing date and time Solved the problem

1
  • 1
    Date and time of what? Could you please be more clear? Mar 20, 2022 at 16:51
0

As far as i have figured out in Apple MackBook Air M1 , you need to click on 'Tools' --> 'Vim Emulator' if it is ticked just untick it . It worked fine for me. As shown in figure just untick it

0

this actually helped me go to 'Tools' and click 'Vim Emulator' if it is ticked untick it

0

In my case, just pressing insert (twice), fixed the problem.

-1

Yes Thanks it is definitely the VIM Emulator. Disable it from the tool menu and you will not loose the ability anymore

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.