๐Ÿš€ OharaLumina

IntelliJ does not show Class when we right click and select New

IntelliJ does not show Class when we right click and select New

๐Ÿ“… | ๐Ÿ“‚ Category: Java

Navigating the rich ecosystem of IntelliJ IDEA often feels like wielding a powerful magic wand for developers. However, even the most seasoned programmers can hit a snag when the expected functionality suddenly vanishes. One particularly frustrating issue arises when IntelliJ does not show ‘Class’ when we right click and select ‘New’, leaving you unable to create new Java or Kotlin classes directly. This common hurdle can halt your workflow, forcing you to find tedious workarounds or question your setup. This isn’t just a minor inconvenience; it’s a productivity killer that can stem from various underlying configurations or environmental quirks within your IDE. Understanding the root causes, from project structure misconfigurations to SDK issues or even corrupted caches, is the first step toward a swift resolution. This guide will walk you through systematic troubleshooting steps, ensuring you can restore the ‘Class’ option and get back to coding efficiently.

Understanding Why ‘Class’ Options Disappear in IntelliJ

When the ‘Class’ option is mysteriously absent from your ‘New’ context menu in IntelliJ IDEA, it often points to a fundamental misunderstanding or misconfiguration within your project’s setup. IntelliJ, being an intelligent IDE, makes contextual suggestions based on the type of project, module, and files you’re working with. If it doesn’t detect a Java or Kotlin environment, or if the project’s structure is improperly defined, it simply won’t offer to create a new class file because it assumes it’s not relevant.

Common culprits include an incorrectly configured Project SDK, where IntelliJ can’t locate a valid Java Development Kit (JDK) to compile your code. Another frequent issue involves the module type itself; if your module is not designated as a ‘Java’ or ‘Kotlin’ module, the IDE won’t present Java/Kotlin-specific file creation options. Furthermore, issues like corrupted IDE caches or even outdated plugin versions can sometimes interfere with the IDE’s ability to correctly parse your project’s context and present all available file types. As an experienced software engineer, I’ve seen these issues derail development sprints, emphasizing the importance of a well-maintained and correctly configured development environment.

Verifying Project and Module Configuration for Java/Kotlin Support

The core of many “IntelliJ does not show ‘Class’ when we right click and select ‘New’” problems lies in the fundamental project and module settings. Ensuring that IntelliJ knows it’s working with a Java or Kotlin project is paramount. This involves checking the Project SDK, the language level, and the module type. Without these correctly set, IntelliJ simply won’t recognize the need to create Java or Kotlin classes.

According to JetBrains, the developers of IntelliJ IDEA, proper project structure configuration is critical for the IDE to function optimally. “An incorrect SDK configuration is one of the most common reasons for various IDE issues,” states their documentation. Properly aligning your project’s SDK with an installed JDK ensures that IntelliJ has the necessary tools to compile and run your code, thereby enabling the creation of relevant file types. Below are the steps to meticulously verify and correct these critical settings:

  1. Check Project SDK: Go to File > Project Structure... (or press Ctrl+Alt+Shift+S). Under ‘Project Settings’ > ‘Project’, ensure a valid JDK is selected for ‘Project SDK’. If not, click ‘New…’ and add a local JDK installation.
  2. Verify Project Language Level: In the same ‘Project Structure’ window, under ‘Project Settings’ > ‘Project’, confirm that ‘Project language level’ is set to an appropriate Java version (e.g., SDK default, 8, 11, 17, etc.) that matches your JDK.
  3. Inspect Module SDK and Language Level: Navigate to ‘Project Settings’ > ‘Modules’. Select your primary module. Under the ‘Dependencies’ tab, ensure ‘Module SDK’ is correctly set (usually ‘Project SDK’). Also, under the ‘Sources’ tab, verify ‘Language level’ for the module.
  4. Confirm Module Type: Still within ‘Modules’, ensure your module is recognized as a ‘Java’ or ‘Kotlin’ module. Sometimes, if a module is imported incorrectly or created from scratch without proper setup, its facet might be missing or incorrect. If necessary, add a Java or Kotlin facet by clicking the ‘+’ button and selecting ‘Java’ or ‘Kotlin’.
  5. Check Source Roots: For your module, under the ‘Sources’ tab, ensure that your directories containing source code (e.g., src/main/java, src/main/kotlin) are marked as ‘Sources’ roots (blue folder icon). IntelliJ only offers new file types within designated source folders.

After making any changes, click ‘Apply’ and ‘OK’. Then, try right-clicking on your source folder again. Often, these fundamental adjustments resolve the missing ‘Class’ option immediately. For more detailed guidance on configuring your Java environment, you can always refer to the official IntelliJ IDEA documentation on SDKs.

Addressing Common IntelliJ-Specific Glitches and Cache Issues

Even with perfectly configured project and module settings, IntelliJ IDEA can occasionally encounter internal glitches that prevent certain functionalities from appearing. These issues are often transient and can stem from corrupted caches, indexing problems, or even minor conflicts with third-party plugins. When you find that the ‘Class’ option is still missing after checking your project structure, it’s time to delve into some common IDE-specific troubleshooting steps.

If you’re facing an issue where IntelliJ does not show ‘Class’ when you right-click and select ‘New’, it’s highly probable that your IDE’s internal caches have become corrupted or are out of sync with your project. Invalidating caches and restarting IntelliJ IDEA is a well-known first aid step for a wide array of IDE anomalies, including missing context menu options. This process forces IntelliJ to re-index your entire project and rebuild its internal data structures, often resolving the underlying inconsistencies that lead to the ‘Class’ option disappearing.

Here are crucial steps to address these internal IDE problems:

  • Invalidate Caches and Restart: This is the most common fix for many IntelliJ quirks. Go to File > Invalidate Caches / Restart.... In the dialog, select ‘Invalidate and Restart’. This will clear IntelliJ’s internal cache and restart the IDE, forcing it to re-index your project. This often resolves issues where the IDE is not correctly parsing your project’s context.
  • Check for Plugin Conflicts: Sometimes, recently installed or updated plugins can interfere with core IDE functionalities. Go to File > Settings > Plugins (or IntelliJ IDEA > Preferences > Plugins on macOS). Try disabling any recently added or suspicious plugins one by one, restarting the IDE after each, to see if the ‘Class’ option reappears. You can also refer to community discussions on platforms like Stack Overflow for known plugin issues.
  • Rebuild Project: Sometimes, the project’s build artifacts might be out of sync. Go to Build > Rebuild Project. This will clean and recompile your entire project, which can resolve internal inconsistencies.

These actions ensure that IntelliJ has a fresh perspective on your project, clearing out any stale data that might be causing the ‘Class’ option to be hidden. It’s a quick and Question & Answer :

We’re creating a new project in IntelliJ and must have something wrong because when we right click on a directory, select New and then get the context menu, Java based options are not shown. Currently get things like File, some HTML options, XML options.

We have assumed so far it’s something we haven’t configured correctly in the Project/Module configuration. The new module we are talking about is part of a multi module project. We created it using a Maven web archetype.

Any help configuring the project nature?

Edit: The answer is basic: ‘That moment when you realise somethings not working because you haven’t been clicking ‘Apply’… :) We had a good laugh at ourselves when we discovered this’

The directory or one of the parent directories must be marked as Source Root (In this case, it appears in blue).

If this is not the case, right click your root source directory -> Mark As -> Source Root.

๐Ÿท๏ธ Tags: