文章目录
- 报错场景:
- 报错原因:
- 解决方法:
报错场景:
IDEA运行Java项目报错,点击运行之后,IDEA在编译代码的时候就出现报错:
报错类型一:java: 错误: 不支持发行版本 21
报错类型二:java: 错误: 无效的源发行版:21
详细报错如下:
Executing pre-compile tasks...
Running 'before' tasks
Checking sources
Copying resources... [spring6-ioc-annotation]
Checking dependencies… [spring6-ioc-annotation]
Dependency analysis found 0 affected files
Updating dependency information… [spring6-ioc-annotation]
Searching for compilable files... [spring6-ioc-annotation]
Parsing java… [spring6-ioc-annotation]
java: 错误: 不支持发行版本 21
Dependency analysis found 0 affected files
Errors occurred while compiling module 'spring6-ioc-annotation'
javac 17 was used to compile java sources
Finished, saving caches…
Module 'spring6-ioc-annotation' was fully rebuilt due to project configuration/dependencies changes
Compilation failed: errors: 1; warnings: 0
Executing post-compile tasks...
Compilation failed: errors: 1; warnings: 0
Synchronizing output directories...
2024/3/5 10:28 - Build completed with 1 error and 0 warnings in 4 sec, 114 ms
截图如下:
报错原因:
Javac编译器的版本与JDK版本不对应
解决方法:
参考以下文章:
IDEA切换JDK版本详细步骤
保持文章里面4大点的版本一直即可:
- ①File——>Project Structure——>Project;
- ②File——>Project Structure——>Modules;
- ③File——>Project Structure——>SDKs;
- ④File——>Settings——>Build, Execution, Deployment——>Compiler——>Java Compiler。
例如,我这里是第四点的版本不一致: