150

Under the target folder in IntelliJ for a Java project I created, I have a few java source files in the package. Beside each file the 'J' icon has a red circle with a line through it.

What does that mean? How do I fix it?

aliteralmind
  • 19,847
  • 17
  • 77
  • 108
TERACytE
  • 7,553
  • 13
  • 75
  • 111
  • 4
    The answer you were given is correct but not full. Intellij replace C with J if the source file is not under a defined src folder or if the file is too big. I explain [Intellij Icons](http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CCwQFjAA&url=http%3A%2F%2Fblog.mograbi.info%2F2011%2F05%2Fintellij-j-is-shown-instead-of-c.html&ei=BGC0UMmgGcbotQb734H4AQ&usg=AFQjCNFZQBEUJPL1XehFkUaJH41wrsuKjQ) in my blogpost. – guy mograbi Nov 27 '12 at 06:42
  • Possible duplicate of [intellij icon over project files](http://stackoverflow.com/questions/2728333/intellij-icon-over-project-files) – Jim G. May 17 '16 at 12:04

20 Answers20

183

You need to specify the source dir

File> Project Structure > Modules

click the directory and click the Sources button

It's weird because usually it's done automatically. Maybe it's better if you recreate the project again.

ItamarG3
  • 4,092
  • 6
  • 31
  • 44
irreputable
  • 44,725
  • 9
  • 65
  • 93
  • 1
    Please, i can't find Sources tab, Modules contains (Properties, Signing, Flavors, Build Types, Dependencies)...thank you very much. – Mohamed Seif Feb 13 '16 at 14:19
  • 2
    With "Android Studio" this can happen when you use 'flavors'. The build variant will determine what files are in the source dir, so changing the build variant can change which files have the mentioned icon – CrandellWS Apr 02 '16 at 00:47
  • Good answer, thank you, also with IntelliJ version 15.0.1 there are examples of the folder structure to the right in the sources view. – Bob Small May 16 '16 at 16:40
  • I've tried this with the wrong folder (`src`) but I guess it was too high in the hierarchy, all my imports went wrong. If you have the same problem, try this with another folder. – Zoette Dec 21 '16 at 00:27
  • This is happening every time I add Gradle to my existing java project. Hopefully, IntelliJ will fix it soon. – Sai Mar 15 '18 at 11:52
66

If it is a maven project

  1. right click on the pom.xml
  2. Add As Maven Project

Thanks

Djalas
  • 1,031
  • 9
  • 6
50

The first answer from irreputable above that starts out with "you need to specify the source dir" is correct, but I don't see him telling you the easy way to do so.

Simply right click on the java sources folder ("java" under src/main/java if it is a Maven project for example) and select Mark Directory As > Sources Root (see screenshot below).

enter image description here

Eric Green
  • 1,151
  • 9
  • 17
8

This situation happens when the IDE looks for src folder, and it cannot find it in the path. Select the project root (F4 in windows) > Go to Modules on Side Tab > Select Sources > Select appropriate folder with source files in it> Click on the blue sources folder icon (for adding sources) > Click on Green Test Sources folder ( to add Unit test folders).

Hari Palappetty
  • 539
  • 6
  • 14
5

First mark the directory as the source root. Then go to the pom excel and right click on it. select add as maven project .

4

Find all IntelliJ (v15) symbols over here: https://www.jetbrains.com/idea/help/symbols.html

This site states that this icon stands for "Java class located out of the source root. Refer to the section Configuring Content Roots for details."

Marged
  • 10,577
  • 10
  • 57
  • 99
crazyGuy
  • 338
  • 2
  • 15
3

Another option if you're using Flavors in Android Studio:

Click Build -> Select Build Variant.

In the list click the variant you're working in and it will turn green and the others will have the red J.

Dunfield
  • 785
  • 6
  • 11
3

As mentioned earlier,

  1. right click on the pom.xml

enter image description here

  1. Add As Maven Project

enter image description here

Arefe
  • 11,321
  • 18
  • 114
  • 168
2

Press F4 at the project root and select the the root source pressing the source button. It resolved my problem!

for(; ;){
  makeGoodCode();
}
1

I downloaded a project from github with .idea folder. After deleting that folder, everything was ok.

Shoham
  • 7,014
  • 8
  • 40
  • 40
1

Actually this can happens because of two reason.

  1. Your project not getting/ Updating your dependencies. Go to your terminal and enter mvn clean install. Or right click on pom.xml and click Add as Mevan Project.

  2. Check your jdk has set properly to the project.

Das_J
  • 71
  • 2
  • 9
1

This was killing me as I had the same issue. I just going over old projects. Really redoing old lessons from class to get more practice. The repos just have compatibility issues. So I import the project. Then add the source like others state. Then close the project. Delete the .idea directory in the root and re-import project.

Spillz
  • 11
  • 2
0

mark the java folder as source root.It will solve.

Mukund BS
  • 1
  • 1
0

It means those files aren't part of the project settings.

0

Maybe your project has not been as android project by android studio, please make sure that plugin 'android support' has been enabled(Android Studio Preferences -> Plugins -> Select Android Support)

Max
  • 111
  • 1
  • 4
  • Close Android Studio and delete .idea and .gradle folder from project structure and start Studio again. – Ramakant Apr 03 '19 at 12:37
0

Close Android Studio and delete .idea and .gradle folder from project structure and start Studio again.

Ramakant
  • 206
  • 2
  • 7
0

It means your Java source files aren't part of the project.

If the suggestions mentioned here don't resolve the issue, you may have hit a rare bug like I did. Researching the exceptions found in the log helped me. In my case, disabling the "Plugin DevKit", deleting the .idea directory, and reimporting the project worked.

user3325776
  • 105
  • 2
  • 10
0

This is what worked for me

  1. Press File from the toolbar
  2. Press Sync Project with Gradle Files
0

For a gradle project "./gradlew --stop" will help to resolve the problem when the source directory is correctly specified and project is properly synced.

Soma Kundu
  • 33
  • 5
0

I used Repair IDE on file and it worked. I did this for every file which has j icon. Check screenshot.

enter image description here

KESHAV KUMAR
  • 140
  • 1
  • 7