1

Here is my code

package com.a;
public class A{}

I compiled using

javac -d . A.java

I gets compiled in com/a/A.claas

Now I created another class

package com.b;
import com.a.A;
class B extends A{}

compiled it with javac -d . B.java and throwing error

B.java:2: error: cannot find symbol
import com.a.A;
        ^
symbol:   class A
location: package com.a
B.java:3: error: cannot find symbol
class B extends A{}
              ^
symbol: class A
2 errors

Can anybody help?

1 Answer 1

2

The compiler is checking your code, and since you're only compiling class B and not class A at the same time, the compiler throws an error because it doesn't know what A is. So either compile all your classes at the same time with

javac -d . A.java B.java

Or tell javac where to find class of A with the -classpath option. The classpath you specify should either be a .jar file that contains A, or the base directory of your class structure. I.e. if your class A is at /foo/bar/com/a/A.class, your classpath would be /foo/bar/

javac -classpath . -d . B.java

Check out the man page for javac as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.