aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes cannot find symbol error during compilation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "cannot find symbol error during compilation" Watch "cannot find symbol error during compilation" New topic
Author

cannot find symbol error during compilation

Mudit Handa
Greenhorn

Joined: Dec 17, 2009
Posts: 1
i have two files 1) MyClass.java 2)Another.java

Directory Structure D:\chap10\com\foo

Both files are in foo folder

MyClass.java contain following code

package com.foo;
public class MyClass
{
public void hi() {System.out.println("hi?");}
}

Another.java contain following code

package com.foo;
import com.foo.*;
public class Another {
void go() {
MyClass m1 = new MyClass();
com.foo.MyClass m2 = new com.foo.MyClass();
m1.hi();
m2.hi();
}

public static void main(String [] args)
{
Another an = new Another();
an.go();
}
}

Following error occur when Another.java is compiled

D:\ExamPractice\com\foo>javac Another.java
Another.java:9: cannot find symbol
symbol : class MyClass
location: class com.foo.Another
MyClass m1 = new MyClass();
^
Another.java:9: cannot find symbol
symbol : class MyClass
location: class com.foo.Another
MyClass m1 = new MyClass();
^
Another.java:10: cannot find symbol
symbol : class MyClass
location: class com.foo.Another
MyClass m2 = new MyClass();
^
Another.java:10: cannot find symbol
symbol : class MyClass
location: class com.foo.Another
MyClass m2 = new MyClass();
^
4 errors

Refer to example on page 769 SCJP study guide by Kathy Sierra & Bert Bates
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18717
    
  40

Since your classpath is likely not set... trying compiling as so...

D:\ExamPractice>javac com\foo\Another.java


Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
is there any need to for the import statement when both the classes are in the same package?
wont compiler give error. I use eclipse and it just dont let me write this kind of import statement.


SCJP 1.6 96%
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

yes in the same package we don't need import statement.


SCJP6 96% | SCWCD5 81% | SCDJWS5 79%
 
Consider Paul's rocket mass heater.
 
subject: cannot find symbol error during compilation