Search code examples
javamethodscallprivatepublic

java call public method from private class


I need to call a private constructor from a public class from a library like this:

public class XMLRoutine {
    private static XMLRoutine _instance;
    private XMLRoutine() {
    }
    public String signXml(String xml, PrivateKey privateKey, Certificate cert, String encoding) throws ParserConfigurationException, SAXException, IOException, PrivilegedActionException {
    }
}

When I try to call it like this:

import kz.softkey.iola.applet.XMLRoutine;
...
XMLRoutine xmlr = new XMLRoutine();

I get an error: XMLRoutine() has private access in XMLRoutine, so I cant call method signXml.

How can I solve this problem?


Solution

  • XMLRoutine has private constructor. So you can't create using new XMLRoutine(). it might have getInstance() method for creating new singleton object or some other static methods that you can use instead of creating the object of the same class