23

my android studio gone crazy like this please help??

file was loaded in the wrong encoding: 'UTF-8' in android studio

file was loaded in the wrong encoding: 'UTF-8' in android studio

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
Waqar Vicky
  • 373
  • 1
  • 3
  • 12

13 Answers13

34

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.

Akshay Chouhan
  • 335
  • 3
  • 6
  • 1
    Works. Thanks. in my case the folder name is 'caches' and not 'cache' – Gal Rom Feb 19 '20 at 13:21
  • 2
    Just updating my path for other users so that they can quickly go to caches directory. C:\Users\\.AndroidStudio3.6\system\ . Worked for me as well. :-) – droidd Mar 09 '20 at 05:54
  • 1
    Works for me Before deleting, closed IDE. deleted all files in C:/userfolder/.AndroidStudioVersion/system/caches Thanks. – Manju Jul 15 '20 at 02:58
  • I want to emphasize that it worked by deleting only the files inside caches. I left the folders inside intact. – YoussefDir Oct 03 '20 at 17:15
  • 1
    Worked perfectly. Thanks @Akshay Chouhan – KSR Jan 22 '21 at 07:25
  • On Windows this path is now C:\Users\[username]\AppData\Local\Google\AndroidStudio[XXXX.X]\caches (see also @Francis' answer). Thanks Akshay, this worked for me! – Jorn Rigter Dec 29 '21 at 12:36
21

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.

M Shaban Ali
  • 348
  • 2
  • 13
  • 2
    Thanks a lot, UpVoted for saving my day, and for those who are facing this problem, :- before doing anything, just take a backup then do whatever you want to do and **Don't forget to try @MShabanAli's solution** – Ravi Vaniya Jun 27 '19 at 07:15
  • Happy to help :) – M Shaban Ali May 02 '20 at 22:26
  • if you don't have backup ----> you can also cut the code which gives error and than paste it again to the same location that also solved my problem. – Abdul Wahid Oct 06 '20 at 14:05
9

In my case it happend after Windows died with the blue screen, here's how I fixed it:

  1. Close Android Studio
  2. Find a directory named .AndroidStudioX.X in C:Users/YourUsername and rename it to old.AndroidStudioX.X
  3. Restart Android Studio and choose the renamed old.AndroidStudioX.X to import settings from.

My answer is taken from here https://stackoverflow.com/a/53476487/4277741

ulmaxy
  • 820
  • 2
  • 14
  • 22
8

On Windows close Android Studio and delete its cache directory:

c:\Users\[user name]\AppData\Local\Google\AndroidStudio[XXXX.X]\caches
Francis
  • 6,788
  • 5
  • 47
  • 64
4

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

Harsh0021
  • 362
  • 3
  • 11
3

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.

Benny
  • 2,233
  • 1
  • 22
  • 27
1

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

Mussa Charles
  • 659
  • 7
  • 10
1

I had to replace unknown characters(which I had in a comment) into known ones. The issue happened after resolving merge conflicts.

unknown chars

James121
  • 81
  • 10
0

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.

0

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.

saeed foroughi
  • 1,662
  • 1
  • 13
  • 25
0

This worked for me, I clicked on utf-8 and code is displayed in proper format.

Ashwini Salunkhe
  • 224
  • 2
  • 12
0

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.

Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73
-1

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.

f1sh
  • 11,489
  • 3
  • 25
  • 51