Android Studio project doesn't recognize some classes

China☆狼群 提交于 2020-01-14 05:51:07

问题


Recently my project got messed up. I don't know how it became like this. There was no power failure or anything happened while using Android Studio. Next day I opened my project and now it's a full mess. I attached the images of how they look now.

Classes are not recognized as you can see they have .java extension showing and when I opened one of them it show like below. but if I opened the file directly from notepad or something the source-code of these files are not changed.

I did delete .idea all .iml files inside the project then invalidate & restart build project again. But no luck, no matter what I did it doesn't get resolved. I have an old backup of this project and not a recent one, so I want to get this fixed .

I tried opening my other projects and they work very well. The problem seems to be only in this project. Android Studio is updated to last version before this problem persisted. So it's not also a bug in Android Studio.

This is how the Java file looks when I opened with Notepad++. The code didn't disappear, no I also didn't write xml code in my Java file:


回答1:


I have same problem occur few days ago, solved by below steps

  1. uninstall android studio,

  2. download latest from link

  3. delete all file from default android studio folder (C:\Program Files\Android\Android Studio)

  4. install new downloaded android studio , all worked well.




回答2:


I just had to copy all the source code in .java files back into android studio editor, which the files are with .java extension. Problem solved




回答3:


I had a similar problem, but with Kotlin files.

What worked for me was shortening the file name by a few characters (but not the class name).

I suspect that there's a limit to the length of the path which can get quite long if you try to organise a large(ish) project using subfolders.



来源:https://stackoverflow.com/questions/53664073/android-studio-project-doesnt-recognize-some-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!