Java – symbol error not found in CMD, but not in IDE

I'm trying to compile the following code (I need one of the two files to complete this job), but I encountered 2 errors in CMD This is what CMD thinks of 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

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

Strangely, the whole thing works well in NetBeans What did I do wrong here?: nine

Solution

Don't build carrental, or if you've compiled it, don't tell the compiler where to find it The IDE may assume that you want to build everything, so it doesn't matter

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

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

... or put the previously compiled output directory in the classpath for later compilation, such as

javac -d classes src\CarRental.java
javac -d testclasses -cp classes test\CarRentalTest.java
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>