选中java 文件所在的package右键选中Mark Directory as---Sources Root
若此时运行时弹出:
cannot start compilation:the output path is not specified for module specify the output path in the project structure dialog
出现该错误是在intelliJ IDEA 中创建项目之后没有指定项目编译输出的地方,指定位置即可。如下图: