报错过程

今天运行带有main函数的java文件时,报错:editor does not contain a main type

解决报错:editor does not contain a main type

明明有main函数,但是为什么会报错呢?

问题分析

逐一排查问题发现:原来java类没有写到src里面的包里,如下图:

解决报错:editor does not contain a main type

问题解决

方式一:

把java类移入src包下就行了

解决报错:editor does not contain a main type

方式二:

有可能src不是包,而是一个文件夹(文件夹的图标比包的图标少一个“田”字)如下图:

解决报错:editor does not contain a main type

这时候,右键文件夹--build path--Use as Source Folder就行啦!

解决报错:editor does not contain a main type

OK, GAME OVER !

相关文章: