Daniel Kaplan
Daniel Kaplan

Reputation: 67340

Why isn't intellij giving me the option to create new classes?

Here's what I'm seeing:

enter image description here

Normally I can choose "New Java Class" but for some reason I'm not getting this option. I created this project by opening an empty directory and building it out from there. I've seen this question, but that answer didn't help me. Here's my module settings:

enter image description here

Even if I open my pom.xml directly as a project, it still has this problem. How do I fix this?

Upvotes: 2

Views: 4176

Answers (4)

Jay Teli
Jay Teli

Reputation: 1012

This worked for me :

  1. Right click the java folder (myproject/src/main/java)
  2. Click "Mark Directory as"
  3. Click "Source Root"
  4. Right click the myproject folder (myproject/src/main/java)
  5. Click "Mark Directory as"
  6. Click "Source Root"

So basically had to mark some inner folder as Source project and alter mark parent project again as Source project.. Hacky way but this worked for me.

Upvotes: 3

Pranavi Chaturvedula
Pranavi Chaturvedula

Reputation: 41

This happened when I was trying to add classes to a generated package using xjc plugin.

Intellij allows to add classes only to packages which are correctly names and have the "source root" status.

Can be fixed as-> right click on the directory where you're not able to add classes:

Mark sources root refer image for clarity

Upvotes: 0

Bindiya
Bindiya

Reputation: 31

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.

Upvotes: 3

Daniel Kaplan
Daniel Kaplan

Reputation: 67340

For some reason, intellij didn't recognize my directories as packages. If I created something directly from the java directory, it would give me the correct options. I fixed this by deleting everything under java/ and recreating it. This may be an intellij bug.

Upvotes: 1

Related Questions