Reputation: 393
my android studio gone crazy like this please help??
file was loaded in the wrong encoding: 'UTF-8' in android studio
Upvotes: 24
Views: 37357
Reputation: 7104
On Windows close Android Studio and delete its cache directory:
c:\Users\[user name]\AppData\Local\Google\AndroidStudio[XXXX.X]\caches
Upvotes: 8
Reputation: 10549
Just rename the project folder and reopen it in Android Studio, worked like a charm!
Invalidate Cache & Restart / Clean & Rebuild doesn't work for me. The project cache corrupted after improper s/m shutdown. Just change the project dir path renaming the project, it'll work.
Upvotes: 0
Reputation: 81
I had to replace unknown characters(which I had in a comment) into known ones. The issue happened after resolving merge conflicts.
Upvotes: 1
Reputation: 849
This is an old one but I just click Invalidate Cache / Restart
on file option in IDE and after restart, it works.
Version Android Studio v4.1
Upvotes: 2
Reputation: 335
An encoding issue can be solved by deleting all files contained in the Android Studio "caches" folder, which can be found in "C:\Users<username>.AndroidStudioX.Y\system\caches".
Make sure that to close Android Studio before deleting.
Upvotes: 34
Reputation: 2331
All you need is to remove the Android Studio settings directory, which can be found:
on Windows
C:/Users/yourusername/.AndroidStudioX.Y
on Linux:
/home/yourusername/.AndroidStudioX.Y
Close Android Studio, delete the directory, then reopen Android-Studio and open your project.
Also if it happens on a different IDE, it is the same approach.
If the issue persists, try to copy the content of your project directory into a new directory, then open the project from the new directory.
Upvotes: 3
Reputation: 230
This worked for me, I clicked on utf-8 and code is displayed in proper format.
Upvotes: 0
Reputation: 372
you have to just delete the catches folder in C:/users/"your PC name"/AndroidStudio(version code). Sometimes it gets disturbed because of some reasons like you have shut down the PC in improper way so it won't get enough time to shutDown all stuff So all that errors occurs.
I think it would definitely work for you. Have a nice day!!!! :)
Upvotes: 4
Reputation: 1
I had the same problem and how I fixed it is that I just went to the directory where the java files for my project are located, which in my case is users/user name/AndroidStudioProjects/Project name/app/src/main/java/com/example/android/project name
, and here you will find all java codes you wrote for your project just open the one making the problem with notepad and you will find your code here in the right format and perfect just copy all of it and get back to Android Studio window and delete the wrong formatted code and paste this one and wait for it to sync and that's it. If you face the same issue with XML codes just do the same thing find the directory where XML files are located.
Upvotes: 0
Reputation: 870
In my case it happend after Windows died with the blue screen, here's how I fixed it:
My answer is taken from here https://stackoverflow.com/a/53476487/4277741
Upvotes: 9
Reputation: 105
This is an old issue, but if anyone comes across this, what isn't mentioned above, but happening for me is that the original file on disk is intact java code. Android Studio is reading it like this for some reason.
Upvotes: 0
Reputation: 357
For people in future:
I had the same problem.
I was able to solve it simply by making a copy of the project and opened the copied project. Copied project worked perfectly fine.
Note: I got this problem because of improper shutdown of my PC.
Upvotes: 21
Reputation: 11944
That's not an encoding issue. That's compiled bytecode, the content of a .class file. You cannot simply rename it into .java and expect it to work.
Upvotes: -1