1

In short, I'm trying to instantiate within the main method in order to handle computations. I wrote the main class in Eclipse and was able to compile and run everything smoothly.

Main Method:

public static void main(String[] args)
{
    ...

    OutsideClass class = new OutsideClass();

    ...
}

I ran it in eclipse, which worked smoothly until I got an error due to to insufficient privileges, which led me to switch over to using cmd.exe as an administrator.

I navigated to the eclipse folder where I had all the classes saved to and ran javac x.java for each file in the folder, one by one. I was able to do javac OutsideClass.java without any errors, though when it came to javac Main.java, I received the following error:

Main.java:36: error: cannot find symbol
                    OutsideClass outside = new OutsideClass();
                    ^
symbol:   class OutsideClass
location: class Main
Main.java:36: error: cannot find symbol
                    OutsideClass outside = new OutsideClass();
                                          ^
symbol:   class OutsideClass
location: class Main
2 errors

The OutsideClass doesn't have a defined constructor, though I don't know if that really matters or not.

Oleg Silkin
  • 508
  • 1
  • 5
  • 12

1 Answers1

0

The Java compiler needs the source (.java) or bytecode (.class) of OutsideClass when compiling Main.java.

Try javac *.Java, or javac -cp OutsideClass.class Main.java to provide OutsideClass's definition to the compiler when compiling Main.

It is more customary for Java developers to compile all Java sources of a single project via one javac invitation, either directly, or via a tool such as Maven.

Mark A. Fitzgerald
  • 1,249
  • 1
  • 9
  • 20