Intellij - 错误 JAVA(导入等)未检测到 [英] Intellij - Errors JAVA (imports, etc...) doesn't detect

查看:24
本文介绍了Intellij - 错误 JAVA(导入等)未检测到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用 IntelliJ-IDEA,但我的 java 文件没有检测到例如导入等错误.我没有创建一个项目 java,因为我在同一个项目中使用不同的语言,但我希望在 java 文件中,他检测到错误.我该怎么做?

I'm starting use the IntelliJ-IDEA, but my java files doesn't detect errors like imports for example. I don't create one project java, because i'm using different languages in same project, but I want that in the java files, he detect the errors. How can I make this?

推荐答案

Intellij 可以很好地工作于标准项目布局.如果您的不是标准的 - 告诉 Intellij 它的结构:从打开的工作区中,选择文件 -> 项目结构 (Ctrl+Alt+Shift+S),然后浏览所有选项卡以设置细节:

Intellij can work very well standard project layouts. If yours is not standard - tell Intellij how it is structured: from open workspace, select File -> Project Structure (Ctrl+Alt+Shift+S), and go through all the tabs to setup specifics:

最重要的标签可能是:

  1. 项目选项卡,您可以在其中指定要与项目一起使用的 jdk(如果您愿意,则为 JAVA_HOME)
  2. 模块 -> 告诉 intellij 哪些目录应该被视为 java 包的来源
  3. 模块 -> 设置编译类的路径
  4. Modules -> Libraries - 指定要使用的任何其他 jar.

假设您的项目中有两个 java 文件:

Assume you have two java files in your project:

package com.myproject // this one have package

public class SomeClass{
    //whatever
}

public class Main {
    // whatever - no package
}

所以你应该将它们放在某个目录中:

so you should have them inside some directory:

directory
  |- com
  |  |- mypackage
  |     |- SomeClass.java
  |- Main.java

在这种结构中 - 目录 是源根目录.标记为这样

In such structure - the directory is sources root. Mark it as such

这篇关于Intellij - 错误 JAVA(导入等)未检测到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆