Question

Why am I getting this error when the SystemController class is in the same directory?

sgs$ javac Main.java 

Main.java:27: cannot find symbol
symbol  : class SystemController
location: class sgs.Main
        SystemController sc = new SystemController();
        ^
Main.java:27: cannot find symbol
symbol  : class SystemController
location: class sgs.Main
        SystemController sc = new SystemController();
                                  ^
2 errors

package sgs;

import javax.swing.JFrame;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        boolean loginSuccess = false;
        //Login login = new Login();
        //login.setVisible(true);
        //login.loadAccounts("files/accounts.txt");

        SystemController sc = new SystemController();
    sc.setVisible(true);
        sc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}
Was it helpful?

Solution

My guess is that you didn't compile SystemController on which Main depends. So either compile manually SystemController before to compile Main (but that will be painful on the long term if the number of classes grows) or compile everything together and let the compiler calculates the compilation order (better IMO). Something like this:

$ pwd
/path/to/sgs
$ cd ..
$ javac sgs/*.java
$ java -cp . sgs.Main

EDIT: From the error you posted as comment, I can see that you are using GNU GCJ which doesn't fully support Swing. Please switch to Sun JDK or OpenJDK. Both should be available as package, just make sure to make it the default Java after install (see https://help.ubuntu.com/community/Java for Ubuntu or a Debian based distro, find out how to do this for another distro).

OTHER TIPS

Have you compiled SystemController ?

try

javac *.java

Also, remember to specify your classpath where the Swing classes are.

javac -cp classpath *.java
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top