Lint checking doesn't work for Java but works for Kotlin in Android Studio

Viewed 609

I've been using Kotlin for a long time, but recently I opened a Java project and I noticed that Android Studio isn't recognizing the Java code properly as the same as Kotlin. For example when I write Java code the lint checking isn't working at all. I'm having a hard time knowing what errors I made and what classes need importing and even the code style isn't applied as the settings.

On the other hand, when I create a Kotlin class on the same project, everything works well.

I've tried opening multiple Java projects and it's the same thing, so it's not a project-specific issue.

Keeping in mind that the project works well and runs without any problem as long there are no errors in the code.


Here's pictures showing the problem:

Java Code: No Errors but code style not applied enter image description here

Java Code: Error found but no erorr highlighting enter image description here

Kotlin Code: No Errors and code style is applied enter image description here

Kotlin Code: Error found and lint is working well enter image description here

3 Answers

I tried all the mentioned answers, but nothing worked. But After some searching, some people on a GitHub issue discussion mentioned having a similar problem and the root cause was some incompatible plugins with Android Studio, so I went through my plugins and uninstall most of the old ones that I don't use and making sure the remaining ones are compatible with my current Android Studio v4.1.3. Then after restarting the IDE, it WORKED.

Please look at this and this threads.

Possible reasons for code highlighting and error prompts not working are disabling inspection in power save mode (which doesn't seem to be in your case as inspection for kotlin works very well) and improper setting.

Please try resetting to default setting as described here Before that you may want to make sure that you are not in power save mode - link

Make sure at least compiler issues box is checked under File -> Settings -> Editor -> Inspections -> Java enter image description here

You can know which values that differ from the default values by:

File -> Setting (CTRL + ALT + S) -> Editor -> Inspections 
                                 -> Show Scheme Actions gear box -> Export

Open the exported xml file, and see what options that set which you can know exactly what goes wrong.

This is a demo content after changing some option:

<profile version="1.0">
  <option name="myName" value="Default" />
  <inspection_tool class="AndroidLintClickableViewAccessibility" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>

And this is whenever the default values are set:

<profile version="1.0">
  <option name="myName" value="Default" />
</profile>

So, now in order to solve the issue you to reset this inspection to the default by

File -> Setting (CTRL + ALT + S) -> Editor -> Inspections 
                                 -> Show Scheme Actions gear box -> Restore Defaults

enter image description here

But before doing this, I would suggest to Export the current settings first so that you can know exactly what is wrong.

Related