Issue
I need to access classes from a separate package from the class I am working on however I cannot get it to work. I am currently working on ConcreteAccount in the PMSModel package and need to access methods from the classes in Account.Strategies.
I keep getting the "Cannot find symbol" error when trying to do this. I have another project that uses the exact same method that I am trying to use and there is no error. I have tried to access them when the classes have constructors and when they do not but I get the exact same error. I have an image of the error below:
Below is the code where I am trying to access the classes from the Account.Strategies package. The error itself is showing on the "Strategies" part of the statement.
package PMSModel;
import Account.Strategies.IAccountStrategy;
public class ConcreteAccount extends Account {
@Override
public IAccountStrategy selectStrategy(String accountType){
IAccountStrategy strategy;
switch(accountType){
case "Patient":
strategy = new Account.Strategies.PatientStrategy();
break;
case "Secretary":
strategy = new Account.Strategies.SecretaryStrategy();
break;
}
return strategy;
}
}
Below is a screenshot of how my packages and classes relate to each other:
I expect "strategy" to store the class so that I can access the methods of that particular class in Account.
Solution
First at all, good practices for naming a package must be written in lowercase. Second the issue that you are facing is because you don't have a root package which should be shared by your project for example :
com.example.projectname
This should be your root and on this starts others packages
com.example.projectname.account.strategies
com.example.projectname.controller
com.example.projectname.guiview
com.example.projectname.pmsmodel
com.example.projectname.resources
FYI I'm agree about what JB Nizet typed you.
REFERENCES
Java Code Conventions -> https://www.oracle.com/technetwork/java/codeconventions-150003.pdf
Answered By - Jonathan JOhx
Answer Checked By - Cary Denson (JavaFixing Admin)