IntelliJ
Java
troubleshooting
IDE
new class issue

IntelliJ doesn't show 'Class' under right-click New: how to fix it

Codemia Knowledge Hub ·

IntelliJ IDEA only offers New > 'Class' in directories it recognizes as part of a source root. If the option is missing, the folder is usually not marked as a source root, is marked as excluded, or the project has no valid JDK. Less often, a file type association or stale caches are to blame.

The folder is not marked as a source root

This is the most common cause. If the directory is not identified as part of a source root, the 'Class' option does not appear.

  1. Go to File > Project Structure > Modules.
  2. Check that your folders are marked correctly. Usually src folders are marked as Sources.

In a standard layout, src/main/java must be marked as Sources for the IDE to offer class operations:

plaintext
1project-root
2│
3├── .idea
4├── out
5├── src
6│   └── main
7│       ├── java
8│       │   └── com
9│       │       └── example
10│       │           └── MyClass.java
11│       └── resources

The folder is marked as excluded

  1. Right-click the folder.
  2. If Mark Directory as shows Excluded, change it to Sources Root.

No JDK is configured

Without an appropriate JDK, Java operations such as adding classes may not be available.

  1. Open File > Project Structure.
  2. Under Project, set the Project SDK to a valid JDK.

Wrong file type association

IntelliJ may associate files or directories with a type that excludes Java operations.

  1. Go to File > Settings (or IntelliJ IDEA > Preferences on macOS).
  2. Open Editor > File Types.
  3. Make sure the file type you are working with is not assigned to an unexpected type.

Stale caches and indexes

If indexing did not run properly, it can interfere with context menu options. Rebuild the indexes by invalidating caches:

  • Go to File > Invalidate Caches / Restart.
  • Choose Invalidate and Restart.

To look for other configuration problems, open IntelliJ's internal log with Help > Show Log in Explorer.

Causes and fixes

IssueCauseSolution
Missing 'Class' optionUnmarked source rootMark correct directories as Sources Root
Unrecognized FilesIncorrect file type associationReconfigure file types under File Types
Java Options MissingNo JDK linkedAssign a JDK in Project Structure
Menu Options MissingFolder marked as excludedUnmark folder as Excluded
Miscellaneous ErrorsCaches and Indexes not updatedInvalidate caches and restart IDEA

Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms