So, I have this code:
package test;
import test.Pi;
public class Demo {
public static int pi = 3;
public static void main (String args[]) {
System.out.println("Hello!");
Pi.main(args);
System.out.println("Hello again!");
}
}
But eclipse keeps throwing up an error at the very first line, saying “The declared package test does not match the expected package”.
Any help apreciated! Thanks!
That’s not a matter of importing – that means you’re trying to declare that the package for this class (
Demo) istest, but the compiler error shows that you’ve got it in the wrong place – you’ve got it in the root of your source path, instead of in a directory calledtestunder the source root.Three possible changes:
Don’t put it in the
testpackage; given the title of your question, it’s not clear whether you were trying to do that or not. You don’t need to import any classes which are in the same package as the class you’re declaring.Move
Demo.javainto atestfolder if it’s not already.If
Demo.javais already in atestfolder, change your build configuration so that its parent directory is the source root.