+ 1
Making instance error Java
I made a public "Cat" class in Java that is used to declare an object or instance(?) named Vanilla in another class called "MyClass" and it worked, i made the "Cat" class and "MyClass" class in two seperated files. But when i do the same thing with a "Vehicle" class and "MyClass", in seperated files too, it got two errors like this : C:\Windows\Java\Car\MyClass.java:3: error: cannot find symbol Vehicle car1 = new Vehicle(); ^ symbol: class Vehicle location: class MyClass C:\Windows\Java\Car\MyClass.java:3: error: cannot find symbol Vehicle car1 = new Vehicle(); ^ symbol: class Vehicle location: class MyClass 2 errors [Finished in 1.2s with exit code 1] What should I do? There is no mistyped/typo..
12 Antworten
+ 1
Fajar Kurniawan
Actually, what you have to add to the PATH environment variable is the folder in which contains the whole JDK, so you can use javac anywhere regardless your cmd current directory. It seems that you add the path of a folder in which you keep your codes, it's fine but not really necessary.
So, it seems that you have no problem running the compiler, but for some reasons (according to your description) the compiler can find MyClass.java but not Vehicle.java
However, this shouldn't happen if Vehicle.java is in the same folder
So, I'll rephrase my question, are you sure that you put both MyClass.java and Vehicle.java in the same folder?
0
Can you show me the code?
0
Well, @Agent_I @Jacob Burgess , Actually when i compile the code files in my "PATH" and "CLASSPATH"(the name of system variable), it works, because both my PATH and my CLASSPATH are C:\Windows\Java, but when i moved the code files into C:\Windows\Java\Car, it's not working, is there any method to solve this problem because i wanted to not run too much code in the same folder
Btw, im running and compiling using cmd
0
Fajar Kurniawan
So, just to be clear, you put those files in this folder, C:\Windows\Java\Car ? Both of them?
0
@Agent_I yes I do.
Sorry, is this a bad question??
0
Fajar Kurniawan
No, it's not. I just need to clarify some things in order to help you. So you said you use cmd to compile it, what did you write excatly, in the cmd?
0
@Agent_I I wrote something like this :
javac Vehicle.java
and no problem, then :
javac MyClass.java
and after that line, i got the errors like what written in the description, but when I did it in other specifiec folder, it actually worked.
I think it's because my "CLASSPATH" in system variables or environment variables..
0
Fajar Kurniawan
That explains why, have you tried to use the full path instead like
javac C:\Windows\Java\Car\MyClass.java
Let's see if that works
0
Jacob Burgess no, it isn't a typo, I mean, when i setup/install the JDK I have to make a system variables (or an environment variables?) called PATH and CLASSPATH so that either the JDK or the JRE knows where is the code file or the class is located, but this makes my flexibility reduced, i should make all the codes in a specified folder and not other folder. Or actually I can add another path to the CLASSPATH and PATH variablesm but it will make cosing more difficult when i have a bigger project other than just learning.
Sorry that i've talked too much, i mean typed too much