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

后端 未结 8 1034
小鲜肉
小鲜肉 2020-12-07 10:26

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 b

相关标签:
8条回答
  • 2020-12-07 11:17

    If you open your module settings (F4) you can nominate which paths contain 'source'. Intellij will then mark these directories in blue and allow you to add classes etc.

    In a similar fashion you can highlight test directories for unit tests.

    0 讨论(0)
  • 2020-12-07 11:18

    There is another case where 'Java Class' don't show, maybe some reserved words exist in the package name, for example:

    com.liuyong.package.case

    com.liuyong.import.package

    It's the same reason as @kuporific 's answer: the package name is invalid.

    0 讨论(0)
  • 2020-12-07 11:19

    This can also happen if your package name is invalid.

    For example, if your "package" is com.my-company (which is not a valid Java package name due to the dash), IntelliJ will prevent you from creating a Java Class in that package.

    0 讨论(0)
  • 2020-12-07 11:24

    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.

    0 讨论(0)
  • 2020-12-07 11:26

    you need to mark your directory as source root (right click on the parent directory)

    and then compile the plugin (it is important )

    as result you will be able to add classes and more

    0 讨论(0)
  • 2020-12-07 11:26

    Project Structure->Modules->{Your Module}->Sources->{Click the folder named java in src/main}->click the blue button which img is a blue folder,then you should see the right box contains new item(Source Folders).All be done;

    0 讨论(0)
提交回复
热议问题