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

Using the Java SDK with TextPad

Moderators: AmigoJack, helios, bbadmin, Bob Hansen, MudGuard

Post Reply
umyangxd
Posts: 2
Joined: Mon Oct 03, 2005 4:41 pm
Location: Edmonton

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

Post 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? -----
User avatar
talleyrand
Posts: 625
Joined: Mon Jul 21, 2003 6:56 pm
Location: Kansas City, MO, USA
Contact:

Post 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]
I choose to fight with a sack of angry cats.
umyangxd
Posts: 2
Joined: Mon Oct 03, 2005 4:41 pm
Location: Edmonton

Post 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?
User avatar
talleyrand
Posts: 625
Joined: Mon Jul 21, 2003 6:56 pm
Location: Kansas City, MO, USA
Contact:

Post 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 ;)
I choose to fight with a sack of angry cats.
henry420
Posts: 1
Joined: Wed Oct 26, 2005 10:35 pm

Post 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
User avatar
s_reynisson
Posts: 940
Joined: Tue May 06, 2003 1:59 pm

Post 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?! ;)
Then I open up and see
the person fumbling here is me
a different way to be
Post Reply