Android Studio“文件已以错误的编码方式加载:'UTF-8'"并且"Java文件未声明任何类".从哪儿冒出来 [英] Android Studio "File was loaded in the wrong encoding:'UTF-8'" and "Java file does not declare any class" out of nowhere

查看:297
本文介绍了Android Studio“文件已以错误的编码方式加载:'UTF-8'"并且"Java文件未声明任何类".从哪儿冒出来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意,我已阅读"

现在,错误首先显示为文件已以错误的UTF-8编码格式加载" ,并提供了许多选项来更改我的编码.现在,作为一名程序员,我知道我是否有任何问题,我应该将其搜索到Google,并找到与该问题相关的所有答案,然后在尝试所有这些答案后,很幸运,我尝试了所有这些答案,上面的错误消失了,只剩下一个警告(?)",说"Java文件未声明任何类" .现在,令人惊讶的部分是,如果它是来自Android Studios代码编辑器的编码错误,那么如果我在另一个文本编辑器中打开它应该就可以了,对吧?我使用"Brackets"&也是记事本",但是我再次被这个美丽的东西所吸引:

现在,我对这里出错的地方一无所知,因为有些类运行良好(大多数是 Activities ),但是其中许多不是活动的,都消失了,变成了这样的东西.这是一场噩梦,我过去两天写的所有内容似乎都消失了(因为我最近一次推送是在两天前,我知道自己很傻).XML文件很好,只有Java文件有此问题.

我尝试过的事情:

  1. 从C:\ Users \ PersonWhoDidntPushChanges \ .AndroidStudio3.4删除Android Studio设置

  2. 使用UTF-16重新加载文件编码,然后再次返回UTF-8.(请注意,只有重新加载不会将内容写在磁盘上并更改原始编码,这有一个不同的选项)

  3. 从项目中删除 .idea 文件夹,然后重新加载项目.

  4. 常用内容,无效的缓存/重新启动,清理项目,重建的项目.

还请注意,在我实际打开此文件之前,应用程序运行良好,Android Studio并没有给我任何错误,当我看到这种格式的文件时,我打开了一堆其他类来查找那些也停止工作的类.关于此事的任何帮助将不胜感激.

我正在使用

  Android Studio 3.4.2版本号AI-183.6156.11.34.5692245,于2019年6月27日建立JRE:1.8.0_152-release-1343-b01 amd64JVM:JetBrains s.r.o的OpenJDK 64位服务器VMWindows 10 10.0 

Android Studio还更改了一些XML文件.我目前发现的唯一解决方案是,用我在Github上完成的一个项目替换整个项目.显然,某些库也已更改(FloatingActionButton).

解决方案

我遇到了同样的问题,经过一番挣扎,我解决了这个问题,所以我在这里共享,以便您也可以解决它.

首先,关闭android studio,然后删除其中的AndroidStudio文件夹存储在c派生中.

例如:-C:\ Users \ XXXX

现在,您需要打开android studio并安装所有要询问的文件Android Studio.

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:

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:

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).

解决方案

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.

这篇关于Android Studio“文件已以错误的编码方式加载:'UTF-8'"并且"Java文件未声明任何类".从哪儿冒出来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆