Page 1 of 1

JAVA compiler can't find class file in the same folder...

Posted: Mon Oct 03, 2005 4:52 pm
by umyangxd
-----A file called Car.java has the following lines-----
class Car{
int price, year;
public Car(int p, int y){
price = p;
year = y;
}

public int getPrice(){
return price;
}

public int getYear(){
return year;
}
}

-----And another file called testCar.java contains main method, -----

public class testCar{
public static void main(String[] args){
Car c = new Car(2000,1993);
System.out.println(c.getPrice());
}

}

-----No problem in compiling Car.java. However, it gives me the following
-----errors when compiling testCar.java-----

cannot resolve symbol
symbol : class Car
location: class testCar
Car c = new Car(2000,1993);
^
D:\Documents and Settings\yangxingdong\Desktop\testJava\testCar.java:3: cannot resolve symbol
symbol : class Car
location: class testCar
Car c = new Car(2000,1993);
^
2 errors

Tool completed with exit code 1

-----Anyone has idea how to solve the problem? -----

Posted: Mon Oct 03, 2005 9:34 pm
by talleyrand
Just a guess here
http://www.textpad.info/forum/viewtopic ... lve+symbol

Yet another guess
http://www.textpad.info/forum/viewtopic.php?t=4290

Check out this one too, always a useful link. http://www.textpad.info/forum/viewtopic.php?t=4702

[edit]
Additionally, I saved your information out into 2 files as indicated. Compiled Car.java, compiled testCar.java, executed the testCar.class and it printed 2000.

Code: Select all

javac Car.java
javac testCar.java
java testCar
Java 1.4.1
[/edit]

Posted: Tue Oct 04, 2005 6:01 pm
by umyangxd
Thanks!
I followed the 2nd link, and added -classpath "$FileDir;D:" $File to both javac and java. It compiles, but gives "java.lang.NoClassDefFoundError" when I run it. Any solution to this?

Posted: Wed Oct 05, 2005 2:04 am
by talleyrand
Still sounds like the classpath may not be set up correctly. Again, a search for NoClassDefFoundError within the TextPad forums or via Google.

Happy hunting ;)

Posted: Wed Oct 26, 2005 10:47 pm
by henry420
don't let talleyrand discourage you...

there is an easy solution to this problem.
right-click my computer, click properties
select the advanced tab
click the environmental variables button at the bottom
under system variables, there should be a variable named CLASSPATH, if so, change its value to '.' (no quotes, just a period)
if not, click new, and add a variable with name CLASSPATH and value of .

that should take care of your problem, and now in the future if other users search the forums, they might find something useful as opposed to unhelpful posts telling them to perform another search

Posted: Thu Oct 27, 2005 12:56 am
by s_reynisson
"Give me a fish and I won't go hungry today. Teach me to fish and I'll never go hungry again." - Who said that anyway?! ;)