17

Unfortunaetly my laptop shutdown unproperly during coding in Android Studio. When I turned on again and tried to reload the project one class / java file was corrupted and suddenly all code was gone!

What I already tried:

  • Local History -> Show History = nothing to show
  • File / Invalidate Caches and Restart = no luck
  • Decompiled apk, but code has been obfuscated by Proguard, so it is almost impossible to read

Weird thing is that the java file has a size but the content is empty (I already deleted "nul nul nul" characters but still no luck.

Any help or advice?

Sini
  • 406
  • 1
  • 6
  • 16

4 Answers4

51

I once had this issue and the way i solved it was to delete the folder C:\Users\cc.AndroidStudio3.2\system\caches.

i hope this helps

amos godwin
  • 930
  • 9
  • 12
  • 3
    Awesome! My problem was AndroidStudio shows me java files (aparently random) with content in XML from "Find in path" last searches or not logic gradle xml tags... The origin files, but, still showing the correct code. Stop android Studio, delete this folder and start again sovles the problem! I'm using Android Studio 3.3.1. I don't know how this occours but seems relationated with Android Studio cache problem... maybe for a BSOD? Any way... Thanks for your answer! – Joan Casadellà Mar 01 '19 at 14:17
  • 2
    You are welcome @jcasadellaoller .For me BSOD was the problem Tip * always use Version Control – amos godwin Mar 01 '19 at 16:36
  • 1
    Tanks a lot! I was about to completely mental, but it seems like this solved the issue. +1 – Langkiller Aug 01 '19 at 09:06
  • 1
    I also experienced this problem after migrating AndroidX and it worked for me. – mazend Sep 06 '19 at 11:27
  • 2
    Had to comment. a plus one was not enough thank you. used to restore the files one by one from version control and this... am at a loss of words – Richard Muvirimi Sep 11 '19 at 12:04
  • The issue happened suddenly again today.. and I deleted the folder again. I'm not sure why the issue happened again.. – mazend Sep 17 '19 at 08:28
  • 1
    @mazend did your PC have Blue Screen OF Death? – amos godwin Sep 17 '19 at 12:20
  • @amosgodwin Yup. I've been suffering from BSOD for 2 years and the Android Studio issue is happening recently after using Android Studio 3.5. If you want to know my BSOD please refer it: https://superuser.com/questions/1483200/bsod-due-to-driver-power-state-failure-9f?noredirect=1#comment2236959_1483200 – mazend Sep 17 '19 at 15:17
  • @mazend BSOD is the only cause for this issue that I know of at the moment – amos godwin Sep 17 '19 at 15:24
  • @amosgodwin Thank you for the answer. Now I think the BSOD problem is resolved so.. I expect that the Android Studio corruption issue will not happen again. – mazend Sep 18 '19 at 04:46
  • 2
    Damn, this glitch is scary! – Fossor Dec 01 '19 at 12:46
0

In my case there were 2 file 1 had XML code and other had java code. Delete the file that has XML code and rename your Java file the way it was. Solved my problem.

resw67
  • 139
  • 3
  • 6
0

To solve the problem I would cut all the files from the project, allowing android studio to update its indices showing no files in the project tree. Soon after I move them all back then let android studio to load the files again. After loading the cache would get updated with the correct information.

Lenos
  • 11
  • 2
0

What I found was, all the source files are exist in the project directory without any damage, but the Android Studio loads an XML code file. This happened after an sudden turn off of the pc.

Invalidate cache and restart not worked.

I solved the problem by,

Close the Android Studio. Delete the folder C:\Users[UserAccountName].android\cache folder, and then open the Android Studio. Everything worked fine.

Hope this helps someone.

Ruwan Liyanage
  • 333
  • 1
  • 13