Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find symbol error in cmd but not in IDE

Tags:

java

I'm trying to compile the following code (one of two files I need to complete this homework) but I'm getting 2 errors in cmd. This is what cmd throws at me:

CarRentalTest.java:12: error: cannot find symbol
        CarRental myCarRental = new CarRental(); //create CarRental object CarRental
        ^
  symbol:   class CarRental
  location: class CarRentalTest
CarRentalTest.java:12: error: cannot find symbol
        CarRental myCarRental = new CarRental(); //create CarRental object CarRental
                                    ^
  symbol:   class CarRental
  location: class CarRentalTest
2 errors

And this is the code I'm trying to compile.

public class CarRentalTest {

    public static void main (String[] args)
    {
        CarRental myCarRental = new CarRental(); //create CarRental object CarRental
        myCarRental.Customers();

    } //end method main

} //end class CarRentalTest

What's weird is that the whole thing runs fine in NetBeans. What am I doing wrong here? :9

like image 745
Christn Avatar asked Dec 02 '25 06:12

Christn


1 Answers

What am I doing wrong here?

Not building CarRental, or not telling the compiler where to find the class if you have already compiled it. The IDE is probably assuming you want to build everything, so that's fine.

We don't know how your code is organized, but you should either pass all the relevant filenames to the compiler at the same time:

javac -d classes src\CarRental.java test\CarRentalTest.java

... or put the output directory of the earlier compilation in the classpath for the later compilation, e.g.

javac -d classes src\CarRental.java
javac -d testclasses -cp classes test\CarRentalTest.java
like image 190
Jon Skeet Avatar answered Dec 03 '25 20:12

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!