i have two java classes in a package. I want to create one class’s object into another but it gives an error message ERROR: cannot find symbol.
package pckg;
public class aa{
private String name;
public aa(){} //Constructor of aa class
public void setName(String name){this.name=name;}
public String getName(){return name;}
}
package pckg;
public class bb{
aa obj = new aa(); //This line gives error message
public bb(){} //Constructor of bb class
}
both classes are in a same folder pckg.
ERROR Message:
D:\Java\mypack>cd..
D:\Java>cd pckg
D:\Java\pckg>set path=d:\java\jdk1.5\bin
D:\Java\pckg>javac aa.java
D:\Java\pckg>javac bb.java
bb.java:3: cannot find symbol
symbol : class aa
location: class pckg.bb
aa obj = new aa(); //This line gives error message
^
bb.java:3: cannot find symbol
symbol : class aa
location: class pckg.bb
aa obj = new aa(); //This line gives error message
^
2 errors
If you don’t specify a classpath, javac doesn’t know where to find the already compiled classes.
Also, classes should start with an upper-case letter in Java. And I would avoid using the same directory for the source files and class files. You’d better put your sources inside d:\Java\src and your classes inside D:\Java classes. Then, use the following command to compile everything at once: