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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39932158/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:46:54  来源:igfitidea点击:

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

javaandroid-studioencodingutf-8syntax-error

提问by Waqar Vicky

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”

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

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

回答by M Shaban Ali

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.

注意:我遇到这个问题是因为我的电脑关闭不当。

回答by Akshay Chouhan

An encoding issue can be solved by deleting android cache folder. Just visit "C:\Users\.AndroidStdio3.5\" and delete cache folder.

删除android缓存文件夹可以解决编码问题。只需访问“C:\Users\.AndroidStdio3.5\”并删除缓存文件夹。

Make sure that your android studio should be closed before deleting. Reopen your project in AndroidStudio once you finished with this operation, and sync it.

确保在删除之前关闭您的 android studio。完成此操作后,在 AndroidStudio 中重新打开您的项目,并同步它。

回答by Matvey Rybakov

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

在我的情况下,它发生在 Windows 因蓝屏死机后,这是我修复它的方法:

  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.
  1. 关闭 Android Studio
  2. 在 C:Users/YourUsername 中找到一个名为 .AndroidStudioX.X 的目录,重命名为 old.AndroidStudioX.X
  3. 重新启动 Android Studio 并选择重命名的 old.AndroidStudioX.X 以从中导入设置。

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

我的回答来自这里https://stackoverflow.com/a/53476487/4277741

回答by Harsh0021

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.

您只需删除 C:/users/"your PC name"/AndroidStudio(version code) 中的 catches 文件夹。有时它会因为某些原因而受到干扰,例如您以不正确的方式关闭了 PC,因此它没有足够的时间关闭所有东西 所以所有这些错误都会发生。

I think it would definitely work for you. Have a nice day!!!! :)

我认为它肯定对你有用。祝你今天过得愉快!!!!:)

回答by Ashwini Salunkhe

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

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

回答by Benny

All you need is to remove the Android Studio settings directory, which can be found:

您只需要删除 Android Studio 设置目录,该目录可以在以下位置找到:

on Windows

在 Windows 上

C:/Users/yourusername/.AndroidStudioX.Y

on Linux:

在 Linux 上:

/home/yourusername/.AndroidStudioX.Y

Close Android Studio, delete the directory, then reopen Android-Studio and open your project.

关闭 Android Studio,删除目录,然后重新打开 Android-Studio 并打开您的项目。

Also if it happens on a different IDE, it is the same approach.

此外,如果它发生在不同的 IDE 上,则采用相同的方法。

回答by Dharmik Thakkar

Follow the steps in the following answer and your problem will be solved: https://stackoverflow.com/a/57494183/11140751

按照以下答案中的步骤操作,您的问题将得到解决:https: //stackoverflow.com/a/57494183/11140751

回答by f1sh

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.

那不是编码问题。这是编译后的字节码,.class 文件的内容。您不能简单地将其重命名为 .java 并期望它能够工作。

回答by user1930720

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.

这是一个老问题,但如果有人遇到这个问题,上面没有提到,但对我来说发生的是磁盘上的原始文件是完整的 java 代码。出于某种原因,Android Studio 正在像这样阅读它。

回答by Mohammed Hussein

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.

我遇到了同样的问题,我的解决方法是我刚刚转到我项目的 java 文件所在的目录,在我的例子中是users/user name/AndroidStudioProjects/Project name/app/src/main/java/com/example/android/project name,在这里你会找到你为你的项目编写的所有 java 代码,只需打开一个用记事本解决问题,你会在这里找到正确格式的代码,完美只需复制所有代码并返回Android Studio窗口并删除错误格式的代码并粘贴此代码并等待它同步,就是这样. 如果您遇到 XML 代码的相同问题,只需执行相同的操作即可找到 XML 文件所在的目录。