How to compile class in package?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
frlaw
Posts: 1
Joined: Sun May 11, 2003 6:53 am

How to compile class in package?

Post 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
User avatar
jeffy
Posts: 323
Joined: Mon Mar 03, 2003 9:04 am
Location: Philadelphia

Re: How to compile class in package?

Post 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. :(
User avatar
jeffy
Posts: 323
Joined: Mon Mar 03, 2003 9:04 am
Location: Philadelphia

Post by jeffy »

Please use the Java forum in the future. :' )
Post Reply