Thinking in Java problem on Eclipse when importing source files
import java.util.*;
import static net.mindview.util.print.*;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("hello world");
Print("this does not work");
}
in the editor on the x next to the import statement the error is:
The import net cannot be resolved
in the editor when I put my mouse on the x next to the print statement it reads:
The method Print(String) is undefined for the type HelloWorld
when I try to run it in eclipse this is the error I get:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method Print(String) is undefined for the type HelloWorld
at HelloWorld.main(HelloWorld.java:8)
Solution:
So we move to directory structure:
BTW - I assume you're running javac and java commands from the command line, since you didn't suggest otherwise in earlier posts. If that's wrong, describe your environment and compile/run process.
In my environment, I have the directory structure:
main
|- net
| |- mindview
| |------util
| |
HelloWorld.java |
|
Print.java
You have to create a new source folder under the existing folder named 'src'.
In the project explorer right click the folder 'scr' then New then Source folder, name it 'net.mindview.util'
then right click the new folder 'net.mindview.util'
then click new then click package and name it 'net.mindview.util'
then right click on the package named 'net.mindview.util' and select import then select File System in the list
then click next then navigate to the folder 'net.mindview.util' on your hard drive,
there will be two boxes in the import window
the left side will have a folder named 'util' with a check box, if you check this all of the .java files from the 'net.mindview.util' will be imported into your project and everythinng will work.
The box on the right side is all the induvidual .java files and you can pick and choose what files you want to import...
original source:
http://www.coderanch.com/t/566491/java/java/Thinking-Java
main page:
No comments:
Post a Comment