I need to use some methods from a helper class but having trouble when I try to create a object of the helper class in my activity.
HelperClass helper = new HelperClass();
When I do the above I get an error saying I need to make the visibility of Helper() default.
Here is the relevant part of the helper class.
public class HelperClass {
private static HelperClass helperClass;
private String list;
private HelperClass() {
initialiseHelper();
}
When I take out the private in the HelperClass it is fine but I do not want to edit this class. Is there a way around this?
It looks like you’re trying to apply Singleton pattern, but you’re missing the
getInstance()method, which should look like this:Now you should use this method everywhere you want to reference an instance of
HelperClass. Hope this helps.