Page 1 of 1

How to compile class in package?

Posted: Sun May 11, 2003 6:58 am
by frlaw
Dear gurus,

I am trying "package" and struck with the following:-

<Test.java in directory "\test">
import mypackage;

public class Test {
public static void main (String args[]) {
System.out.println("Test");
Test1 test1 = new Test1();
}
}

<Test1.java in directory "\test\mypackage">
package mypackage;

public class Test1 {
public Test1 () {
System.out.println("Test2");
Test2 test2 = new Test2();
}
}

<Test2.java in directory "\test\mypackage">
package mypackage;

public class Test2 {
public Test2 () {
System.out.println("Test2");
}
}

When compiling Test1.java, the following errors occurred:-

E:\test\mypackage\Test1.java:8: cannot resolve symbol
symbol : class Test2
location: class model.Test1
Test2 test2 = new Test2();
^
E:\test\mypackage\Test1.java:8: cannot resolve symbol
symbol : class Test2
location: class model.Test1
Test2 test2 = new Test2();
^
2 errors

Any advice will be appreciated.

Thanks in advance!
:cry: :cry: :cry: :cry: Francis

Re: How to compile class in package?

Posted: Sun May 11, 2003 3:21 pm
by jeffy
frlaw wrote:E:\test\mypackage\Test1.java:8: cannot resolve symbol
symbol : class Test2
location: class model.Test1
Test2 test2 = new Test2();
Make sure you compile Test2 first. In general, compile all things not dependant on anything else first, then work your way through the dependency tree.

You have now touched upon why circular dependencies/usages stink. :(

Posted: Sun May 11, 2003 3:24 pm
by jeffy
Please use the Java forum in the future. :' )