简体   繁体   中英

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

my android studio gone crazy like this please help??

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

文件以错误的编码加载:android studio 中的“UTF-8”

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.

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.

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

On Windows close Android Studio and delete its cache directory:

c:\Users\[user name]\AppData\Local\Google\AndroidStudio[XXXX.X]\caches

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

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.

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

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.

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.

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.

这对我有用,我点击了utf-8 ,代码以正确的格式显示。

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

未知字符

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM