Everything was good. Today, I opened Android Studio, and every kotlin class code and even layout and value files turned into another format like XML. I don't know what kind of strange reason it is.
I have been trying to fix this for 2 days now. even though I opened my files into some other editors(sublime, notepad)but the problem is still there.
I am attaching some screenshots MainActivity.kt.
I also tried these couple of things below
File > Sync project with Gradle files. Result: didn't solve my problem.
File > Invalidated cache/restart. Result: didn't solve my problem.
Try this.
Right-click on the file (e.g.: MainActivity.kt),
then click on "Open In", it will open your explorer window.
At this point open that file, which now you see in your explorer window, in a notepad, make a change (e.g.: adding a space where there is already a blank space)
and save the file.
Now Android Studio should see it correctly or, if not, try to restart Android Studio.
If that works, do the same for all suddenly-changed files.
In visual Studio when I move files into a package on the same original level, the files that I move also remain where they were.
I dragged each of these Kotlin files (AddHappyPlaceActivity and MainActivity) into the "activities" package, then pressed refactor in the screen that appears. I would expect the original files to not appear.
Thanks a lot.
Posting an answer is because I don't have enough reputation.
after refactoring the file actually moves there but it is bug I also have noticed, A copy of the file seems to be present in the old places even after refactoring but after refreshing It is gone.
I'm able to resolve this issue by simply closing and re-opening Android Studio.
It looks like a bug of Android Studio. When I restart Android Studio, the file only was shown in the new location. The copy was disappeared.
Everything was fine. I just built it yesterday. Today, while I opened this most of my JAVA classes code, turned into xml. I don't know what kind of strange reason it is.
I tried 2 options below but nothing worked :
File > Sync project with Gradle files. Result: didn't solved my problem.
File > Invalidated cache/restart. Result: didn't solved my problem.
I attached a screenshot.
I found a solution that worked for me. Keep Android Studio open and go into the file system. Open every java source file and all xml files into some editor(Notepad++) and change something then save the file back to origin.
Now Android Studio detect all files as normal
Android studio: Click on malfunction file then Right-click -> Open in -> Explorer.
Choose your file where was the problem and open them with Notepad.
And change something, like adding the space and save it.
And Sometimes Android studio turns files into UTF8-BOM. It needs to change to UTF-8. You may do with NotePad++ -> Encoding.
I was working in Eclipse with some packages and then suddenly the java editor perspective doesn't show any code and it's blue, just like in the photo bellow:
I tried everything, from resetting the perspective to cleaning the project, even installed a new version of Eclipse. If i select the entire content of the .java file then pass it to a txt file the code is still there.
It seems like after 2 days Eclipse just started working normal.
Just open Windows(Option at the top) --> Show View --> Console.
my android studio gone crazy like this please help??
file was loaded in the wrong encoding: 'UTF-8' in android studio
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:
Close Android Studio
Find a directory named .AndroidStudioX.X in C:Users/YourUsername and rename it to old.AndroidStudioX.X
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
I had to replace unknown characters(which I had in a comment) into known ones. The issue happened after resolving merge conflicts.
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.
This worked for me, I clicked on utf-8 and code is displayed in proper format.
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.
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.