Java 当我们右键单击并选择“新建”时,IntelliJ 不显示“类”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18852425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IntelliJ does not show 'Class' when we right click and select 'New'
提问by Crowie
We're creating a new project in IntelliJ and must have something wrong because when we right click on a directory, select Newand then get the context menu, Java based options are not shown. Currently get things like File, some HTML options, XML options.
我们正在 IntelliJ 中创建一个新项目,一定有问题,因为当我们右键单击目录时,选择新建,然后获取上下文菜单,未显示基于 Java 的选项。目前获取诸如文件、一些 HTML 选项、XML 选项之类的东西。
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.
到目前为止,我们已经假设这是我们在项目/模块配置中没有正确配置的东西。我们正在谈论的新模块是多模块项目的一部分。我们使用 Maven Web 原型创建了它。
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'
编辑:答案是基本的:“当你意识到某些东西不起作用的那一刻,因为你没有点击“应用”...... :) 当我们发现这一点时,我们笑得很开心”
采纳答案by Arnaud Denoyelle
The directory or one of the parent directories must be marked as Source Root
(In this case, it appears in blue).
目录或父目录之一必须标记为Source Root
(在这种情况下,它显示为蓝色)。
If this is not the case, right click your root source directory -> Mark As -> Source Root.
如果不是这种情况,请右键单击您的根源目录 -> 标记为 -> 源根。
回答by Brian Agnew
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.
如果您打开模块设置(F4),您可以指定哪些路径包含“源”。然后 Intellij 会将这些目录标记为蓝色,并允许您添加类等。
In a similar fashion you can highlight test directories for unit tests.
以类似的方式,您可以突出显示单元测试的测试目录。
回答by user3218923
回答by kuporific
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.
例如,如果您的“包”是com.my-company
(由于破折号,它不是有效的 Java 包名称),IntelliJ 将阻止您在该包中创建 Java 类。
回答by Xian Shu
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;
Project Structure->Modules->{Your Module}->Sources->{点击src/main中名为java的文件夹}->点击img是蓝色文件夹的蓝色按钮,然后你应该看到右边的框包含新项目(源文件夹)。一切都完成了;
回答by ShatyUT
Another possible solution is that the project name is not acceptable. For example, creating a project with spaces in the name does not block the project creation but the proper sources are not marked and when those are marked manually, I still was unable to create classes. Recreating the project with hyphens (-) instead of spaces corrected the problem for me.
另一种可能的解决方案是项目名称不可接受。例如,创建名称中带有空格的项目不会阻止项目创建,但没有标记正确的源,当手动标记这些源时,我仍然无法创建类。用连字符 (-) 而不是空格重新创建项目为我纠正了这个问题。
回答by Coder Roadie
Had this issue too. Invalidating Caches/Restart did the trick for me. Please upvote so the the IntelliJ folks take this more seriously. This gives the IDE a terrible UI/UX experience.
也有这个问题。使缓存无效/重新启动对我有用。请点赞,以便 IntelliJ 人员更认真地对待这一点。这给 IDE 带来了糟糕的 UI/UX 体验。