I hibernated my laptop when Android Studio was running and found later that the laptop had been shut down. Now one of my source files is appearing empty in Android Studio an
This is what always works
Step 1. Search your pc for *.apk it will show location of many apks but find the app-debug.apk this is your latest build of your app/project which ram on emulator or physical device (Confirm it by checking its location. it should be in your project folder)
Step 2. After successfully find this apk rename it to zip and open in any zip or rar opener software
Step 3. After extracting you will find classes.dex in root of Extracted folder
Step 4. Download dex2jar latest version
Step 5. Drop the classes.dex file onto de2jar.bat file in dex2jar folder. This will extract a jar from it.
Step 6. Now open this jar file in jd-gui (Download here) and voila you see all the classes you ever had in your latest working project.
This is just a small return gift for all the help i have received from answers from stackoverflow community.
Happy to help :)
I'm not sure what makes it to happen and android studio is far the worst IDE i've worked with (how can a tool dare to edit and save the user files without even ask? the usability team of google deserve a nobel)
But this is what I do to manage solve it...
As soon as you identify an event like this happened close android studio, stop any build in progress and dont try to run the project...
it seams that sometimes the modifications aren't done in the real source file, but android studio is opening some intermediate files instead of the original sources and showing it to you when you open the source... some kind of symbolic link mess
So with android studio closed open the file explorer go to your workspace and create a copy of your project in another directory (as far of android studio as possible)
open your souce files with any text editor and check if they are still okay...
re-open android studio and copy/paste file by file, the contents of the copy project you made to the official project
It is super boring and may take a while depeding of your project size, but i managed to recover over 90% of my files like this
See if Android Studio kept a version in local history.
Go to your java file in Android Studio, and navigate to
VCS -> Local History -> See History
Also, start using version control, like git.
Try in Android studio
Close the android studio move the project to another folder from current folder and reopen app from that folder did the trick for me
Android Studio has a build in file history I would check that first. You will probably find your code there. You can find it if you right click your file.
If there is just a special character (that nul) that remove it with notepad++ and check if that fixes your issue.