Android Studio - 'Cannot resolve symbol' syntax highlighting errors although build is ok

丶灬走出姿态 提交于 2019-11-29 10:43:53

The reason is because I had a '!' symbol in my project path. Apparently, as I learnt now, many Java programs fail due to this reason! :-)

I just renamed the path and it works fine now :-)


P.S.

Thank you @gabriele-mariotti for the gradlew clean suggestion. In fact, that helped me find the real root cause. I was not able to run gradlew from the terminal due to a RuntimeException:

Could not determine wrapper version. at org.gradle.wrapper.GradleWrapperMain.wrapperVersion

But that helped me learn about the effect of '!' symbol on paths, and to the root cause of the problem. Thank you all!

Gladys Sanchez

You can trying:

  • Open Module Settings, change the value of compile SDK version (you can choose the minimum version number)
  • Wait for Android Studio to finish refreshing
  • Make sure you have imported:
    import android.support.v4.app.FragmentActivity

  • Open Module Settings again and you should change back compile SDK version , the original version number before you changed it.

  • Wait for Android Studio to finish refreshing

I had this very same problem with two libraries in our project, com.koushikdutta.ion and uk.co.senab.photoview which are used thoughout our multi-app project but are declared as dependencies deep down a library project. The symptoms were like this:

  • I could perfectly compile and run the application
  • The IDE stubbornly refused to find the classes of these libraries and no navigation to their source code was possible, lots of errors (red bars) were associated with all classes that used them; class usages were highlighted in red, no code suggestions, you name it.

My solution is as follows: first of all, close Android Studio. Then :

cd <your-project-folder>
mv .idea/ .idea-old/ 
mv <projectname>.iml <projectname>.iml-old

re-open Android Studio but select the option "Open an existing Android Studio project". Wait for the project to be reparsed and enjoy perfect cleanness.

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