IntelliJ does not show 'Class' when we right click and select 'New'
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Overview
When using IntelliJ IDEA for development, one might sometimes encounter a problem where the option to create a new 'Class' does not appear when right-clicking within the 'Project' view and selecting 'New'. This issue can be particularly frustrating as creating classes is a common operation, especially in Java-focused projects. This article delves into the possible reasons and solutions for when the 'Class' creation option is missing from the context menu in IntelliJ IDEA.
Potential Causes
Incorrect File System Recognition
IntelliJ IDEA must recognize a directory as part of a source root to offer Java class-related options. If the directory isn't identified correctly, the 'Class' option might not appear.
Solution: Verify the directory structure and ensure that you have correctly marked your source roots.
- Navigate to
File>Project Structure>Modules. - Ensure that your folders are marked accordingly (generally,
srcfolders should be marked asSources).
Incorrect File Type Association
IntelliJ might be misconfigured to recognize files or directories in a way that excludes Java file operations.
Solution: Check and reconfigure the file types associated with your project.
- Go to
File>Settings(orIntelliJ IDEA>Preferenceson macOS). - Look under
Editor>File Types. - Make sure that the file type you are interacting within IntelliJ is not mistakenly assigned to an unexpected type.
JDK Configuration Issues
If IntelliJ is not configured with the appropriate JDK, Java-related operations, such as adding classes, may not be available.
Solution: Ensure a JDK is configured and properly associated with your project.
- Open
File>Project Structure. - Under
Project, verify the Project SDK and ensure it is set to a valid JDK.
Folder Exclusion
If the folder you are right-clicking in has been marked as excluded, that could result in the 'Class' option not appearing.
Solution: Remove the exclusion setting on the folder.
- Right-click the folder in question.
- If
Mark Directory asshowsExcluded, change it toSources Root.
Additional Details
Evaluating Logs
Sometimes, the most systematic way to identify an issue is by looking at the logs.
- You can check IntelliJ's internal logs by navigating to
Help>Show Log in Explorer. Look for any anomalies or configuration issues.
Inspecting IntelliJ Indexes
IntelliJ's indexing process may not have run properly, and this can sometimes interfere with context menu options.
- Re-invoking indexing can be done by invalidating caches:
- Go to
File>Invalidate Caches / Restart. - Choose
Invalidate and Restart.
Code Example
Assume the problem is due to incorrect source root configuration. A properly structured Java project would look like this:
Ensure that src/main/java is marked as Sources in the module settings to allow IDE to recognize it for class operations.
Troubleshooting Table
| Issue | Cause | Solution |
| Missing 'Class' option | Unmarked source root | Mark correct directories as Sources Root |
| Unrecognized Files | Incorrect file type association | Reconfigure file types under File Types |
| Java Options Missing | No JDK linked | Assign a JDK in Project Structure |
| Menu Options Missing | Folder marked as excluded | Unmark folder as Excluded |
| Miscellaneous Errors | Caches and Indexes not updated | Invalidate caches and restart IDEA |
Conclusion
IntelliJ IDEA is a robust IDE, but configuration issues can sometimes lead to inconvenient errors or missing functionality such as the inability to create a new 'Class'. By understanding and addressing potential causes such as root marking, file associations, or JDK configurations, you can ensure a smoother development workflow. Utilize IntelliJ's settings and project structure features to diagnose and rectify such issues efficiently.

