IntelliJ not recognizing a particular file correctly, instead it's stuck as a text file

JavaIntellij IdeaFreemarkerFile Type

Java Problem Overview


There is a freemarker file (ftl) in my IntelliJ project that is incorrectly recognized as a text file. There are many of the same type that are correct.

I am aware of the "Mark as text" option. This may be the original reason this file was marked as text but I am not provided with a "mark as ftl file" option to turn it back, if indeed this is the problem. If I mark other ftl files as txt, I am able to turn them back into ftl files as expected.

Java Solutions


Solution 1 - Java

Please ensure that this file (or a pattern that represents it) is not listed under

SettingsEditorFile TypesText

For OS X

PreferencesEditorFile TypesText

Sometimes the file or pattern are stuck under File type auto-detected by file content instead of Text.

Solution 2 - Java

Step 1: Click "File" ==> "Settings" for Windows or "InterlliJ IDEA" ==> "Preferences" for Mac

Step 2: Expand "Editor" & Click "File Types"

Step 3: You will see all file types on Right. Navigate to the "Text" entry and click it

Step 4: You should able to see your file name on the bottom of "Registered Patterns" (lower box)

Step 5: Remove your file from the "Registered Patterns". The problem should be solved and let you rename with fileName.java

Step 6: If not, delete the file from the project and create it again with name fileName

Source

Solution 3 - Java

In 2020 none of the posted answers worked, here's what did:

  1. Left click the file
  2. On the top toolbar, select File -> File Properties -> Associate with File Type

Solution 4 - Java

OSX:

Preferences > Editor > File Types > Text

Windows:

Settings > Editor > File Types > Text Files

Solution 5 - Java

I had the same problem and none of the above solution solved it. The thing that at the end solved it was by selecting the module and going to the module settings(press F4 on the module name)

Then in the Sources tab, select the "java" folder and press on the Sources button. That tells IntelliJ that the folder in question is a source code folder.

Then select the Test folder and press Tests.

That's it. Then it will recognize correctly the files and show errors as needed.

See below the screenshot.

enter image description here

Solution 6 - Java

I solved the same issue by

Right-click on the file ->  "Override File Type" -> Select the extension type the file has.

Solution 7 - Java

I had this problem with a single SQL file. Thanks to kmoney12's answer, I was able to solve it following these steps (I'm using IntelliJ IDEA 2021.3.2 Ultimate Edition, so the steps are not exactly the same) :

  1. Right-click on the file
  2. In the contextual menu, find and choose Override File Type
  3. Select the correct file type in the list

Solution 8 - Java

You might have by accident edited the template in File and Code Template. Press Ctrl+Alt+S

Under

 Settings -> Editor -> File and Code Templates

For me I changed the FileHeader.java file in includes tab.

Recall which type of template you might have changed earlier and revert it back to default.

Hope it works :)

Solution 9 - Java

My specific java filename was not listed in 'Text files' (IntelliJ 2019.3).

After shutting down IntelliJ, then grepping for the filename in .Intellij2019.3, I found a match here: .Intellij2019.3\config\options\filetypes.xml.

After removing the name, IntelliJ sees the file as Java file again.

Solution 10 - Java

This is what worked for me

Go to

File -> Settings -> Editor -> File Types

Removed my file from File name patterns under Auto-detect file type by content option

Solution 11 - Java

I got this error when I created a new interface BenefitService.java it take as a simple text file. The error looks like this:

Unable to parse template “Interface”

Error message: Selected class file name ‘BenefitService.java’ mapped to not java file type ‘Auto-detect file type by content`

So just go IntellJ File -> Settings -> Editor -> File Types->Auto detect file type content and remove your file name eg in my case BenefitService.java it will work

Solution 12 - Java

There's another reason for a file not being coloured in. I've found RubyMine can get stuck analyzing a file, and then it doesn't colour it in. For me this happens on .html.slim files when RubyMine gets confused translating/fetching keys from yml files, for example when implying yml files in both views and controller on a single view file.

Renaming the file appears to fix it, but that's because it no longer gets stuck resolving the yml files, but you think it's the file association problem.

Another way to test it is to comment everything out, using / in the case of slim. Then close file and re-open. It is then coloured for being commented. Remove the comments and it works because Rubymine doesn't try to resolve yml data after the file is opened. But closing then re-open and it gets stuck again as it gets confused.

Solution 13 - Java

I had the same problem to creat a new class java, the issue was on Header.java that can be access with the command crt+alt+s and go to Editor/FileAndCodeTemplates/Includes and this may be on this format:

/**

  • Created by Alex Leporoni on ${DATE}. */

This is solved my issue, now I can create classes again :) I hope that this article can help others that have the same problems to creat classes on IntelliJIdea... hugs to all.

Solution 14 - Java

Workaround: Rename the file without changing the file extension.

FileName.java
NewDifferentFileName.java

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionktamlynView Question on Stackoverflow
Solution 1 - JavaVicView Answer on Stackoverflow
Solution 2 - JavaEvilInsideView Answer on Stackoverflow
Solution 3 - Javakmoney12View Answer on Stackoverflow
Solution 4 - Javamatt burnsView Answer on Stackoverflow
Solution 5 - Javaisaac.hazanView Answer on Stackoverflow
Solution 6 - JavaHernanView Answer on Stackoverflow
Solution 7 - JavaToddEmonView Answer on Stackoverflow
Solution 8 - JavaGurusharan GuptaView Answer on Stackoverflow
Solution 9 - JavaYDZOGODOQView Answer on Stackoverflow
Solution 10 - JavaIamVickyAVView Answer on Stackoverflow
Solution 11 - JavaRavi ShewaleView Answer on Stackoverflow
Solution 12 - JavaNode NoodlerView Answer on Stackoverflow
Solution 13 - JavaAlex LeporoniView Answer on Stackoverflow
Solution 14 - JavaCoffeeTimeView Answer on Stackoverflow