Reputation: 9458
I'm not quite sure what I'm doing wrong, here. I have two files in a directory, let's call them FileA.java and FileB.java.
FileA.java has a definition along the lines of:
package com.domain.package;
import stuff;
import package.FileB;
public class FileA extends Blah implements Listener {
/* global vars */
/* methods */
}
FileB.java is my data object class, which I'd like to reference from FileA.java thusly:
Map<Object, FileB> varname;
to be used along the lines of:
varname = new HashMap<Object, FileB>();
FileB.java, on the other hand, is defined as such:
package com.domain.package;
import stuff;
public class FileB {
/* global vars */
public FileB() {
/* stuff */
}
}
Why am I getting:
FileA.java:20: package package does not exist
import package.FileB;
? Rather, how do I make it work?
Upvotes: 1
Views: 524
Reputation: 9458
@rgettman has the correct solution. Compiling both files using javac FileA.java FileB.java
solves this issue. You can also use his suggestion: javac *.java
Upvotes: 0
Reputation: 96444
package
is a reserved word, don't use it as part of a package name. If you try to add a package with "package" as part of it in Eclipse, you will get an error message:
Invalid package name. 'package' is not a valid Java identifier
Rename the package, then remove the import statement. You don't need to import a file that's in the same package as the one it's referenced in.
Upvotes: 1
Reputation: 178323
Because both files are in the same package (com.domain.package
), you should not need to import FileB
at all. You should be able to reference it directly.
Additionally, please ensure that both FileA
and FileB
are placed in their package folder: com/domain/package.
Upvotes: 1
Reputation: 11185
The package of FileB is com.domain.package
. You are trying to use package.FileB
instead.
Upvotes: 1