1

Please note that I've read "File was loaded in the wrong encoding:'UTF-8' in IntelliJ IDEA" this, and everything else related to this issue that I'm having which is going to make me rewrite everything that I did in my project in past 2 days.

Now, the only reason I'm asking this question, is because if someone else faces this problem in future, it'd possibly have a solution by then?

So here is the problem:

I was working on my app which is already present on Play Store, I made all the changes in code, and wanted to add stuff in old java file. But, I was suddenly greeted with this beautiful thing:

Error in Android Studio

Now, the error first said "File was loaded in the wrong encoding UTF-8" and gave me bunch of options to change my encoding. Now, as a programmer, I know if I have any issues, I should Google them, and found all the answers related to this issue, and I tried all those, fortunately, after trying all those answers, above error was gone, and only one "warning(?)" remained saying "Java file does not declare any class". Now, the amazing part is, if it was encoding error from Android Studios Code editor, it should have been totally fine if I opened it in another text editor right? I opened it using "Brackets" & also "Notepad", but I was again greeted with this beautiful thing:

Screenshot of Brackets Text Editor

Now, I'm totally clueless as to where I went wrong here, as some classes are working fine (most of those are Activities), but a lot of them which are not activities, are all gone and have become something like this. It's a nightmare and everything I wrote in past 2 days seems to have gone(because my last push was 2 days ago, I know I'm dumb). XML files are fine, and only Java files have this problem.

Things I tried:

  1. Deleting Android Studio settings from C:\Users\PersonWhoDidntPushChanges\.AndroidStudio3.4

  2. Reloading File encoding with UTF-16 and then again back to UTF-8. (Please note that only Reloading does not write the contents on disk and change the original encoding, there's a different option for that)

  3. Deleting .idea folder from the project, and reloading the project.

  4. Usual stuff, Invalidate Caches/Restart, Clean Project, Rebuilt Project.

Please also note that app ran fine and Android Studio did not give me any error until I actually opened this file, and when I saw this file in such format, I opened bunch of other classes to find those stopped working too. Any help regarding this matter would be appreciated.

I'm using

Android Studio 3.4.2
Build #AI-183.6156.11.34.5692245, built on June 27, 2019
JRE: 1.8.0_152-release-1343-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

EDIT 1: Some XML files were also changed by Android Studio. The only solution that I found currently is just replacing the complete project with the one that I had on Github. Apparently some of the libraries have also changed (FloatingActionButton).

Vedprakash Wagh
  • 3,595
  • 3
  • 12
  • 33
  • can you try the following, 1)File -> setting -> reset defaults and also invalidate cache and restart after that – Aniruddha K.M Jul 13 '19 at 04:35
  • @war_Hero Reset defaults might do the same thing as removing .AndroidStudio file from C:\Users\Username. Deleting .AndroidStudio basically removes everything and Android Studio is like fresh install. – Vedprakash Wagh Jul 13 '19 at 11:50

2 Answers2

0

I found the solution. Just click on that activity... As in my case it is Main3Activity Right click and open in explorer. The open the file in notepad ++ and copy paste to again android studio.

0

I have faced the same issue and after some struggle, I solved the issue so I am sharing here so that you can also solve it.

First of all, close the android studio and then delete the AndroidStudio folder which are stored in c derive.

Eg:- C:\Users\XXXX

Now you need to open android studio and install all the file which are asking by Android Studio.