I want to run my code without creating a package in java eclipse IDE.
But when I do so it is showing error :
Must declare a named package because this compilation unit is associated to the named module 'Games'
I want to run my code without creating a package in java eclipse IDE.
But when I do so it is showing error :
Must declare a named package because this compilation unit is associated to the named module 'Games'
In the file in question, right click to get the context menu. Select "Refactor->Move". The resultant dialog will have the (default package) into which the source file may be placed.
Also, be sure to not have a package definition line at the start of the source file.
Please note that the use of the default
package is generally discouraged, but there are time I still use it (primarily for printing copyright/version information).
There are also options for turning on hidden/suppressed parent packages, but I think the Refactor approach is the most clean.
You are using the Java Platform Module System (JPMS) which requires not to use the default/unnamed package.
In the default package delete the file
module-info.java
to not use JPMS and to be able to have code in the default package.