Intellij does not show 'Class' when we right click and select 'New'
Swiftly rectify the missing 'Class' option in IntelliJ by invalidating caches: head to File > Invalidate Caches / Restart... and confirm with Invalidate and Restart. This action forces IntelliJ to replenish its index, bringing back the 'Class' option.
Marking directories as source roots
If the 'Class' omission persists, confirm that your directory is rightly identified as a 'Source Root'. IntelliJ needs this to recognize where Java classes belong in the project structure.
To accomplish this:
- Right-click on your project's root source directory in the Project pane.
- Navigate to Mark As.
- Select Source Root.
After IntelliJ consumes the change, look for the directory turning blue in the project explorer — a sign that the folder is now a Source Root.
Inspecting module configurations
Incorrect module configurations can hide the 'Class' option in the 'New' context menu. To access the module settings, tap F4
, or trek through File > Project Structure > Modules, making sure your source paths are set up like a champ.
- Point out the 'java' folder in
src/main
as your Source Folder. - For multi-module projects, ascertain your Maven web archetype is on track.
- Reward smart behavior: compile your project after setting the new source root.
Validating package naming rules
Ensure all package names are Head Boy candidates, strictly adhering to Java's naming conventions. Unwanted characters and typos often play the villain, depriving you of the 'Class' under 'New'.
Unraveling project structure
A jumbled-up project structure can work like a Confundus Charm. A careful examination can deliver you from the maze:
- Traverse the specific module in the project structure to mark the source root.
- It's good housekeeping to differentiate unit test directories from main source sets. They appreciate the highlight.
For all directories you intend to add classes to, ensure each is rightly marked and visually identifiable through the blue coloration.
Tweaking project/module configurations
The best games follow the rules. Save your module and project configurations by applying changes and clicking the 'OK' button. Ignored or canceled actions can result in a continued 'No Class' situation.
Making use of IntelliJ help resources
There is no shame in seeking help. The IntelliJ documentation and visual guidance within the IDE are like Hermione in the library — always ready with the right answers. Do not hesitate to reference them while battling the class creation issue.
Was this article helpful?