Stephan van Hulst wrote:Good on ya for sticking with it. Have a cow!
Stephan van Hulst wrote:Hold on. I'm glad it worked, but it's not correct.
It's very likely that the src/ folder acts as a root folder for your package hierarchy. This means that the Main class must be part of the com.company package. The fact that Main.class is output in the bin/ folder directly means you haven't declared it as being inside the com.company package.
While it might work now, you will run into problems as soon as your Main class starts referencing other classes.
The solution is to put the following statement at the top of your source file, and then use my original java command to run the application:
Double-check that Main.class is output in bin/com/company/.
Stephan van Hulst wrote:Can you tell us what's inside the bin/ folder? Is there a Main.class inside the bin/ folder, or is there a com/company/Main.class file in the bin/ folder?
Stephan van Hulst wrote:Please read my instructions carefully.
Stephan van Hulst wrote:Try the following. From the project3 directory, run the following commands:
Stephan van Hulst wrote:
John Andrew-Mike wrote:javac: directory not found: bin
This means you must make an empty bin folder in the project3 folder.
Stephan van Hulst wrote:Again, your current working directory needs to be the project3 folder.
The src/com/company/Main.java path that you pass to the javac command is relative to the project3 folder, so that's why that folder needs to be the current working directory.
Stephan van Hulst wrote:Again, your current working directory needs to be the project3 folder.
The src/com/company/Main.java path that you pass to the javac command is relative to the project3 folder, so that's why that folder needs to be the current working directory.
Stephan van Hulst wrote:
John Andrew-Mike wrote:but the javac I did myself worked. it created Main.class. so why doesn't it run?
Because you're in the wrong working directory and didn't specify a classpath.
Stephan van Hulst wrote:
John Andrew-Mike wrote:I put the first in cmd and received: "javac: file not found: src\com\company\Main.java
Because you didn't run the javac command from the project3 folder.
Stephan van Hulst wrote:Yes. But CMD has a "current working directory". It's the currently selected directory, and it's shown to you by the command prompt. The current working directory matters to the behavior of the commands you execute.
Stephan van Hulst wrote:Try the following. From the project3 directory, run the following commands:
Stephan van Hulst wrote:Try the following. From the project3 directory, run the following commands:
Stephan van Hulst wrote:Your directory structure suggests that your main class is part of a package called com.company, yet the source you posted doesn't contain a package statement.
You haven't told us the working directory from which you are running the commands.
You didn't show us how you call the java command.