Android Studio Java Syntax Highlighting Not Working
Asked Answered
S

11

27

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.
Saturable answered 23/4, 2015 at 14:51 Comment(4)
Is the file located in a source root?Romney
Yup! It is located in root. I'll take a look at the link. Thanks.Saturable
That was indeed the issue, I've submitted my answer. Thanks makoto!Saturable
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.Diffidence
S
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.

Saturable answered 23/4, 2015 at 15:14 Comment(2)
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.Lindbom
same. need a slightly more detailed answerChenille
L
34

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

Lenni answered 18/1, 2023 at 16:4 Comment(3)
Nope, didn't help. This started happening after I updated to Flamingo.Ovum
@MarkusK It works with Giraffe. try to update the newer versionShortcut
It also worked for me on Giraffe versionApennines
O
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.

Oppose answered 8/8, 2018 at 19:30 Comment(2)
You saved my day! I just tried that and everything just started working again!Phagy
This helped me, I think that Android Studio (InteliJ IDEA?) get confused by changing a kotlin interface into an abstract class?!Highclass
M
10

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

Moxie answered 7/12, 2023 at 15:33 Comment(2)
This worked for me on Koala feature drop 8. The re-index project step was the one that resolved the issue.Canaster
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.Iconolatry
S
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.

Saturable answered 23/4, 2015 at 15:14 Comment(2)
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.Lindbom
same. need a slightly more detailed answerChenille
M
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.

Marginate answered 18/5, 2023 at 15:1 Comment(0)
C
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.

Cassandra answered 18/6, 2024 at 2:23 Comment(0)
D
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.

Derrickderriey answered 8/4, 2024 at 6:33 Comment(0)
H
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

Hephaestus answered 24/4, 2024 at 8:18 Comment(0)
C
0

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

Cathleencathlene answered 10/6, 2024 at 7:25 Comment(1)
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.Ekaterina
Q
0

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

Quintanilla answered 8/7, 2024 at 15:32 Comment(0)
M
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 )!

Macedo answered 14/7, 2024 at 14:40 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.