Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio java syntax highlighting not working

In android studio's (Version 1.1.0) I'm having issues getting it to highlight .java syntax properly. It is currently only highlighting Keywords, Comma, Semicolon, and comments. Other files types such as .xml are highlighting properly.

I've tried the following things...

  • Reinstalling Android Studio
  • Removing any personal settings
  • In "Settings -> Editor" Changed the colors to anything to see if it worked, under General and Java
  • File -> Invalidate Caches
  • Under File Types I've declared my file as a Java source file.
  • Made sure Power Save Mode was turned OFF.
like image 864
Fier Avatar asked Apr 23 '15 14:04

Fier


2 Answers

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.

like image 153
Austin Ekwebelam Avatar answered Nov 06 '22 20:11

Austin Ekwebelam


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

like image 44
Fier Avatar answered Nov 06 '22 21:11

Fier