javacannot-find-symbol

AccountTest.java:10: error: cannot find symbol


I'm currently learning java and i was trying out an example from my textbook but i can't get it to work. I keep getting the "cannot find symbol" error. This is the code in class Account:

package account;

public class Account {

    private String name;

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

}

And this is for AccountTest:

package account;

import java.util.Scanner;

public class AccountTest {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Account myAccount;
        myAccount = new Account();
        System.out.printf("initial name is %s%n%n", myAccount.getName());

        System.out.println("Please enter the name:");
        String theName = input.nextLine();
        myAccount.setName(theName);
        System.out.println();
        System.out.printf("name in object myAccount is: %n%s%n", myAccount.getName());
    }
}

The error message i get is:

javac AccountTest.java
AccountTest.java:10: error: cannot find symbol
            Account myAccount;
            ^
  symbol:   class Account
  location: class AccountTest
AccountTest.java:11: error: cannot find symbol
            myAccount = new Account();
                            ^
  symbol:   class Account
  location: class AccountTest
2 errors

Sorry for the newbie question and thanks for the help!


Solution

  • I have already done that, when i tried to do javac Account.java it didn't give me an error code.

    You need to specify both classes when you compile from the command line.

    javac -cp . account/*.java
    

    And then

    java -cp . account.AccountTest
    

    to run it.