Not Able To Access Classes From Other Packages

Greetings,

I’ve a project, and I would like it to have multiple packages inside my project. However, when I attempt to access a class from this project, I get this error: MyClass() is not public in MyClass; cannot be accessed from outside package. My class is set to public, I was wondering if the package could be set to private, and if so, how can I set it to public?

Thank You All That Response

— Monkeyonawall —

Without seeing your code, its a little hard to guess. Could you post the line that gives this error?

However, there is no way to mark an entire package non-public. Must be something else. I suspect that you have some code that looks a bit like this: MyClass myThing = new MyClass(); that is the source of the error, no? If that is the case, check the constructor MyClass() as its declared as something other than public. (possibly not intended to be called directly) You will have to either modify the constructor declaration, or use whatever other mechanism the class provides for getting a MyClass object.

My error was at, MyClass myThing = new MyClass(); I decided to put public in front of my constructor, and it work. Thank You, For Your Help.

— Monkeyonawall —

Best do some basic java tutorials before trying to create a game using java.

2 Likes