PDA

View Full Version : Java Problem



DBQ
September 2nd, 2008, 08:34 PM
Hi everybody. I have a strange problem in Java. I have two classes A and B. Class A uses class B inside of it (ie makes instances of it). Both classes belong to the same package (same package declaration on top). When I compile it, class A does not see class B. Says undefined symbol.

This whole thing worked fine in eclipse. Now it does not work when I try to compile it using the command line (javac). Any clues?

Ruhe
September 2nd, 2008, 08:51 PM
Can you post contents of your classes, and how you compile and run them?

Easy examaple how it should work:



package com.ruhe.evil;

public class A {

public A() {
B b = new B();
b.someMethod();
}

public static void main(String[] args) {
new A();
}

}


package com.ruhe.evil;

public class B {

public void someMethod() {
System.out.println("yaha");
}

}


And compile and run commands:


javac com/ruhe/evil/A.java
java com.ruhe.evil.A

DBQ
September 2nd, 2008, 08:54 PM
I cannot post the content of the classes. But I compile them simply like this: javac package_path_from_root A.java.

DBQ
September 2nd, 2008, 09:00 PM
I have realized that my path was too deep. However, now when I compile it I get all the instances of Arrays.copyOf flagged. And I get this error:

A/A.java:123: cannot find symbol
symbol : method copyOf(java.lang.String[],int)
location: class java.util.Arrays
String[] c = Arrays.copyOf(n, e.size() + n.length);
^
Note: A/A.java uses unchecked or unsafe operations.

DBQ
September 2nd, 2008, 09:25 PM
I solved it - need Java 1.6. Thank you for all the advice!