java Intelli-J:无法创建类文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38254612/
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
Intelli-J: cannot create class-file?
提问by Leia_Organa
This is honestly a tiny problem but it's keeping me from proceeding with my small Java practice app.
老实说,这是一个小问题,但它使我无法继续使用我的小型 Java 练习应用程序。
I'm currently practicing making an API call in Java. I was trying to create a simple class file called "Film". However, when I try to create it as a class-file, Intelli-J keeps telling me that it is unable to create a class-file. I'm trying to set this file up in a folder called "models". All of these class files are going to be utilized as part of an app that performs API calls.
我目前正在练习用 Java 进行 API 调用。我试图创建一个名为“Film”的简单类文件。但是,当我尝试将其创建为类文件时,Intelli-J 一直告诉我它无法创建类文件。我正在尝试将此文件设置在名为“models”的文件夹中。所有这些类文件都将用作执行 API 调用的应用程序的一部分。
Is there some naming convention I haven't followed? I've been Googling but haven't really found anything.
是否有一些我没有遵循的命名约定?我一直在谷歌搜索,但还没有真正找到任何东西。
回答by Chad Van De Hey
More directly, based on what @Vishal Jumani touched on, you need to tell IntelliJ what directories are 'source' or 'test' directories.
更直接地,根据@Vishal Jumani 所涉及的内容,您需要告诉 IntelliJ 哪些目录是“源”或“测试”目录。
A directory structure you can use as an example, but you can use whatever you wish.
可以用作示例的目录结构,但您可以使用任何您想要的。
Right click on the directory you wish to mark as 'root' --> find 'Mark Directory As' --> Select 'Sources Root'
右键单击要标记为“root”的目录--> 找到“将目录标记为”--> 选择“Sources Root”
Now you should be able to add java classes in the directory without IntelliJ interrupting you!
现在您应该能够在目录中添加 java 类而不会被 IntelliJ 打断!
回答by Vishal Jumani
This would usually be because of the way your project is setup. It may not be setup correctly to indicate where your source code is.
这通常是因为您的项目设置方式。它可能没有正确设置以指示您的源代码在哪里。
- To setup your project, in the Project Tab, click on the top most folder and select F4. This should bring up the Project Settings dialog window.
- Now click on Modules in the LHS, and then select the Sources Tab on the RHS
- Select your src folder and click on the Sources button, to indicate this is your source folder. Now IntelliJ is aware that this is where your code is.
- Click on Apply and OK. This should close the Dialog Window.
- Now right click on the src folder and then select New -> Java Class to create your Java class
- 要设置您的项目,请在“项目”选项卡中,单击最顶部的文件夹并选择 F4。这应该会打开“项目设置”对话框窗口。
- 现在单击 LHS 中的 Modules,然后选择 RHS 上的 Sources 选项卡
- 选择您的 src 文件夹并单击 Sources 按钮,以表明这是您的源文件夹。现在 IntelliJ 知道这是您的代码所在的位置。
- 单击应用和确定。这应该关闭对话框窗口。
- 现在右键单击 src 文件夹,然后选择 New -> Java Class 来创建您的 Java 类