1.首先,查看sdk是否设置了。可以在 File->Project Structure->Project里面查看并设置。
还要注意sdk与Project language level不对应,也会报错。
若项目中有引用外部的jar包,引入的包需要在 File=》Project Structure=》Libraries 中添加想要引入的jar包。
2.设置src目录为Source Root文件夹类型
我们发现src文件夹为灰色,而正常的项目中src文件夹为高亮蓝色
原来,是IDEA不能自动对源代码识别出来src目录,要我们手动设置:选中src目录=》右键=》make Directory as = Source Root:
3.解决output path路径问题
运行程序时,报错:
Cannot start compilation: the output path is not specified for module "16.【异常、线程】-笔记".
Specify the output path in the Project Structure dialog.
其实这个错误是因为没有设置output的路径,只要修改两个地方的设置就可以了:
1)在Modules设置里勾选”Inherit project compile path”
2)设置Project中的”Project compiler output
选择output 输出路径并在末尾加上 \out