Search code examples
javaeclipseexpected-exception

The declared package "facts" does not match the expected package ""


I am using Eclipse IDE for Enterprise java and web developers. I downloaded some zip file called facts(1) and followed every step in setting up this facts project. When I try to run it on server it showing " ... doesn't match the expected package. I tried by adding import package facts; and also without that! I have also looked similar answer and didn't able to fix that either. FYI i have jdk (16.0.2) currently.

[enter image descripenter image description heretion here]2

enter image description here


Solution

  • As you are using default package for your facts classes like Fact.java, FactList.java, you do not need to import it. However, I think your fact files Fact.java, FactList.java, etc are also failing compilation as the package declaration on those files are not same as the folder structure.

    So please try these:

    1. Make sure that there is no statement

      package xxx.yyy.zzz;

    in your fact classes Fact.java, FactList.java, etc and they are compiling successfully i.e. no errors in those files.

    1. Remove the import statement in FactServlet.java as it is not required.

    But.. according to Java standards using default package is not advisable. Create proper directory structure for your files.