I have the
In package from Princeton loaded into the same directory as my files, and I compiled it.
And, I use the package in my code. But, when I use
import In; somehow I still get an error?
java:7: error: '.' expected
What is the solution to this silly problem?
In order to fix this problem, you either need to add a package declaration to
In.java that is the same as your package (and then simply omit your import statement), or (my recommendation) you need to add a package declaration to
In.java that is different than your package (and move it to the corresponding folder), and then import
In by the name of the package that you've given it.
To make this more concrete:
Add the following to the top of
Then move it to the corresponding "edu/princeton/cs/introcs/in" directory. (Create it if it doesn't exist).
Then, in your file, import it by its qualified name:
Note that, in both of the cases above, you'll need to compile In.java along with your code that uses it (or you need to compile In.java, first, and ensure that it is on the classpath when compiling your code that uses it), and at runtime, you need to bundle In.class with your code (e.g. in the JAR you produce) or similarly guarantee that the byte code for that class (either the .class file or a JAR containing the .class file) are on the class path when executing your compiled code.
The code you linked to has no package.
import In, and somewhere in your code create an instance
In myIn = new In(myUrl);, and you should be good.
Alternatively, modify your copy of "In.java" and make it the same package as you're using for the rest of your code.
Look at the
main() in the code for examples of how to use class "In".