Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Corrupted .java file after improper shutdown

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 and in Wordpad as well. When I open it in Notepad++, it shows NUL character. The file has the same size as it had before which means that the file content is not lost (hopefully).

How do I recover the actual content of this file? I need this as I didn't have a backup of this file.

like image 786
cout_display_name Avatar asked Apr 07 '15 19:04

cout_display_name


2 Answers

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.

like image 112
Eric S. Avatar answered Nov 08 '22 23:11

Eric S.


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 :)

like image 12
Lakhwinder Singh Dhillon Avatar answered Nov 09 '22 01:11

Lakhwinder Singh Dhillon