Intellij - Errors JAVA (imports, etc…) doesn't detect

杀马特。学长 韩版系。学妹 提交于 2019-12-02 13:29:06

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:

The most important tabs are probably:

  1. Project tab, where you specify jdk to use with the project (JAVA_HOME if you will)
  2. Modules -> Sources where you tell intellij which directories should be treated as java packages
  3. Modules -> Paths to setup where you want to put compiled classes
  4. Modules -> Libraries - to specify any additional jars to be used.

Assume you have two java files in your project:

package com.myproject // this one have package

public class SomeClass{
    //whatever
}

and

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!