Java program works with IDE but not command line

I was working with a simple program and when I run it from the IDE it works 100% as intended, but when I try to compile it with javac from the command line it says:

C:\Users\Lukasz\Documents\NetBeansProjects\NetBeansTest\src\netbeanstest>javac M
ain.java
Main.java:19: error: cannot find symbol
            MainFrame myFrame = new MainFrame();
            ^
  symbol:   class MainFrame
  location: class Main
Main.java:19: error: cannot find symbol
            MainFrame myFrame = new MainFrame();
                                    ^
  symbol:   class MainFrame
  location: class Main
2 errors

      

However, I'm not sure what might be missing since all files are in the same directory. This is what my main looks like:

public class Main {
    public static void main(String[] args) {
            MainFrame myFrame = new MainFrame();
            myFrame.setVisible(true);
    }
}

      

As you can see, nothing complicated. Line 19 is where the error is MainFrame myFrame = new MainFrame();

, but I don't see what the error could be with it as it compiles the file in the IDE.

Any help here would be much appreciated.

+3


source to share


2 answers


You are compiling Main.java

which has a file dependency MainFrame.java

.

Try compiling and creating a file .class

for MainFrame

before compilingMain.java



To compile a directory use:

javac dir1/*.java 

      

+1


source


You are only compiling one file. The compiler was not informed about the existence of the file containing the MainFrame class.



+1


source







All Articles