Sini
Sini

Reputation: 406

Android Studio java file gets corrupted

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:

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?

Upvotes: 17

Views: 6956

Answers (4)

Ruwan Liyanage
Ruwan Liyanage

Reputation: 375

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.

Upvotes: 0

Lenos
Lenos

Reputation: 11

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.

Upvotes: 0

amos godwin
amos godwin

Reputation: 956

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

Upvotes: 51

vareste
vareste

Reputation: 445

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.

Upvotes: 0

Related Questions