30

In Android Studio (Version 1.1.0) I'm having issues getting it to highlight .java syntax properly. It is currently only highlighting Keywords, commas, semicolons, and comments. Other file types such as .xml are highlighted properly.

I've tried the following things...

  1. Reinstalling Android Studio Removing any personal settings
  2. In Settings -> Editor Changed the colors to anything to see if it worked, under General and Java
  3. File -> Invalidate Caches
  4. Under File Types I've declared my file as a Java source file.
  5. Made sure Power Save Mode was turned OFF.
4
  • 2
    Is the file located in a source root? Commented Apr 23, 2015 at 14:56
  • Yup! It is located in root. I'll take a look at the link. Thanks. Commented Apr 23, 2015 at 15:06
  • That was indeed the issue, I've submitted my answer. Thanks makoto! Commented Apr 23, 2015 at 15:14
  • i have changed my kotlin-gradle-plugin version from 1.5.21 to 1.5.20 in classpath of build.gradle of app and its working fine. Commented Sep 14, 2021 at 4:23

14 Answers 14

41

You should do invalidate caches and restart. It will work.

Sign up to request clarification or add additional context in comments.

4 Comments

Nope, didn't help. This started happening after I updated to Flamingo.
@MarkusK It works with Giraffe. try to update the newer version
It also worked for me on Giraffe version
worked in Android Studio Iguana
16

To solve this kind of issue, I had to trigger: File -> Repair IDE

2 Comments

This worked for me on Koala feature drop 8. The re-index project step was the one that resolved the issue.
Having this issue w/ Koala 2024.1.1 and have tried everything (including Repair IDE steps) and it keeps coming back on certain files. No clue what to do.....AHA!!! I found I had disabled the JetPack Compose plugin so I re-enabled that. I also disabled then re-enabled all plugins and restarted Android Studio. This is what worked for me.
12

I ran into this problem today. In my case it was caused by Android Studio changing my "MainActivity.java" file from a Class to a Singleton. If the file is a Class its icon in the editor or project listing will have a "c" in a light blue circle. If it is a Singleton it has a "j" in a grey rectangle. To resolve it I did the following:

  1. copied the file's contents into notepad
  2. deleted the singleton file BUT I did not select "safe delete" since I don't want Android Studio to do anything clever
  3. created a new Java Class file with the same name as the original file
  4. replaced the contents of the new file with what I put into notepad in step 1

Then everything started working again.

Before this I'd tried the invalidation/restart and disabling power save mode but they did not work for me. I even tried rebooting my computer several times.

2 Comments

You saved my day! I just tried that and everything just started working again!
This helped me, I think that Android Studio (InteliJ IDEA?) get confused by changing a kotlin interface into an abstract class?!
7

If you have installed SQLDelight plugin on your Android Studio, uninstall it. It will resolve your problem, and install SQLDelight again when you need that.

4 Comments

it works for my case
it works for my case too.
same , it worked ;
5

The .java file was located in the root directory. I moved the file to the directory src/main/java/org.we/ and the syntax started working.

2 Comments

I'm having the same issue with Android Studio 2.2.3, but I don't exactly understand the answer you submitted. Where should the Java source files be located relative to the source root for the syntax highlighting to work? Right now my files are right in the source root directory, and nothing works.
same. need a slightly more detailed answer
3

To quickly refresh or enable syntax highlighting, I accidentally did: Ctrl + Alt + S to go to settings, then in Plugins -> Installed disable any plugin and then Enable it and Apply.

This worked for me.

Comments

2

None of these worked on the 2024 version. I had to uninstall Android Studio, clear all caches and application support on Mac, and reinstall it again to solve this issue.

Comments

1

1. Remove cache

(in my case it happened on macOS)

rm -rf ~/.gradle/cache/*

2. Execute the following steps

  1. open the target file on Android Studio
  2. ctrl + a
  3. ctrl + x
  4. ctrl + s
  5. ctrl + v

3. Restart Android Studio

It works for me.

Comments

1

My issue were two new Grazie plugins I enabled. Disabling them solved the problem

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

i had the same problem and tried almost anything i could. Then i realized i had a folder named "app", after moving "src" folder out of app the problem was fixed.

enter image description here

after moving the folders

enter image description here

Comments

0

Deleting the Android Studio app and then re-downloading it worked for me.

Comments

0

Please remove and reinstall Android Studio. I had installed multiple versions of Android Studio, and it was my problem. I deleted all of these and installed the new version (Koala); everything is fine now( on mac )!

Comments

0

TL;DR - disable the Package Checker plugin. Or maybe all plugins to see if it helps at all (kinda, run IDE in the "safe mode")


Longer story below:

I had a very similar problem, quite irritating one, and this question is the closest to what I had. So writing my findings here - maybe it will help someone else too.

I have IntelliJ Community Edition (tried versions from 2022 to 2024) in a corporate environment, behind firewalls, proxies, etc, i.e. probably quite tough environment for the IntelliJ which might try to access network for various reasons, with some sites and HTTP requests working and some not.

Anyway, one day the syntax hightlighting and overall the code inspection went out of the window. Correct parts of the files might be red, incorrect are not highglighted. Cleaning up cache the did not help. Re-cloning the repo, full reinstall and upgrading to the latest version of IntelliJ did not help.

In the IntelliJ logs, I saw this exception at pretty much every startup:

SEVERE - #c.i.c.d.i.PassExecutorService - java.lang.IllegalArgumentException: JBAccountInfoService is unavailable 
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: JBAccountInfoService is unavailable 
  at  java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
  at  com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:80)
  at  com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:57)  
...

So, looked like highlighting was stumbling upon some account problem?? It was very puzzlying.

Fortunately, the answer above about the Grazie plugin gave me the clue. Disabling Grazie did not change the situation for me, but gave me an idea to disable all the plugins, which suddenly returned the situation back to normal.

After switching the various plugins on/off, I found the culprit - for me it was the Package Checker plugin. Some bundled plug-in, I don't even know what it's doing, and I got absolutely no idea why it affects the highlighting.

Also, after a closer examination of the call stack for the exception mentioned above, I found that indeed it comes out of that plugin, since there were these lines too:

...
  at com.intellij.packageChecker.service.PackageChecker$Companion.getInstance (PackageChecker.kt:311)
  at com.intellij.packageChecker.service.HeadlessSynchronizationService.<init>(HeadlessSynchronizationService.kt:32)
...

Just, iniatially I did not pay attention to these packageChecker lines because nothing there gives a clue that it's some kind of a plug-in (it says just com.intellij.packageChecker! Just that was not enough to catch my eye). But, now when I know about this plug-in - the exception definitely comes from it, as the call stack says.

Anyway, disabling the Package Checker plug-in helped me. If someone else's got a similar story and disabling the Package Checker plugin does not help, I'd recommend to disable all the plugins first - if it helps, find the bad boy by switching them on and off with binary search approach.

Comments

0

Just be sure your plugin version and lib version in gradle file are the same. I realize my sqlDelight version vas 2.0.0 in gradle file but my plugin version vas 2.0.2. When I changed 2.0.0 to 2.0.2 it worked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.