0

I have the classes created, I'm trying to

FilePostProcessFactory PostProcessFactory = new FilePostProcessFactory();
FilePostProcess filePostProcess = PostProcessFactory.getFilePostProcessName(fileName);

filePostProcess.getFileConfig(fileId, postProcessInstructions);

This method: getFileConfig is giving me an error: is not public in packageName'. Cannot be accessed from outside package

I was reading this: https://www.javatpoint.com/factory-method-design-pattern

and they have implemented there that the abstract void getRate(); can be accessed from another class outside of the package.

What am I missing?

Thank you

Arturo
  • 3,254
  • 2
  • 22
  • 61
  • All the classes there run with the _default_ access modifier. Related: https://stackoverflow.com/questions/3530065/what-is-the-default-access-modifier – Tom Aug 05 '19 at 21:08
  • Have you *tested* that their getRate() method can be accessed from ouside of the package of Plan? – JB Nizet Aug 05 '19 at 21:08
  • @JBNizet nop but I'm pretty sure it's on the same package. That's why it has access, But the whole point of my code is to create a different package – Arturo Aug 06 '19 at 00:44
  • Then make the method public, as the error message tells you. Pretending that some other code does something that it actually doesn't won't fix your problem. – JB Nizet Aug 06 '19 at 06:21

3 Answers3

0

Change the package of a class from which you're calling it to be the same as the package of the target class, then the error will dissappear. You could also use reflection, and call setAccesible(true) on the method reference, then invoke it.

Krzysztof Cichocki
  • 6,294
  • 1
  • 16
  • 32
0

Try declaring the class public or do what Krzysztof mentioned.

Rumi
  • 196
  • 7
0

I ended up renaming the class: public abstract class myClassName{...}

That fixed it

Arturo
  • 3,254
  • 2
  • 22
  • 61