I just started learning, and I follow what the video said to type out all the code, but I got the error message said cannot find the symbol. Is there anyone know why the Array symbol cannot be found? I create my own package name, but I did choose the Array from the one I create.
Appricate for help!
And you have an import statement at the top of your Main.java e.g.
Because these classes are in the same package, I think you might not need the import statement. If you remove it, does it make a difference?
Interesting thing is I grab Mosh’s source code, and run the code, and got the same error message.
I think you have to compile the Array class first in order for that to work which typically looks like this (not sure if it is different on Windows):
# Alternatively, just the two classes you need:
# javac Array.java Main.java
Then you would run the compiled Main class’s bytecode:
I believe running the command you ran is only compiling
Main.java (rather than including all of its dependencies):
NOTE: you can probably also do this in your IDE (looks like IntelliJ) there by right clicking on the
main method in
Main.java and then selecting whatever option the IDE has for running the Java code (possibly need to add an extension first).
Thank you for your suggestion, using the right click to run the program, then it works.
but I still can’t use the terminal to run the program directly.
Actually, it looks like IntelliJ printed out the exact command line it executed in the terminal if you want to try copy-pasting that. If Java is in the
PATH variable, you should not need to specify the full path to
"C:\Program Files\Java\...\java.exe") and can just use
-javaagent:... flag also looks optional if you want to drop that flag.