0

I have created a series of plugins for imageJ using the interface PluginFilter. Many of these plugins share some common tasks and I would also like to instantiate them outside of imageJ so I created an abstract Analysis.java that contains a constructor

public Analysis(ImagePlus imp){
populateDBValues(imp);
}

but no default constructor. Other plugins extend Analysis. I previously had repeated code in each of the plugins and this worked fine. When the constructor was added I got an error in ImageJ showing the message "Unable to load plugins".

I tracked this through the source code to the point

catch (InstantiationException e) {log("Unable to load plugin (ins)");}

Why does the addition of the constructor cause this error?

1 Answer 1

0

From Default constructors and inheritance in Java "Java provides automatically for you a default constructor (one without parameters), which initializes all instance variables of the class (if there are any) with some default values (0, null, or false). If you write a constructor, however, with some parameters, and you don't write any default constructor, then Java does not provide a default constructor."

Before creating the constructor with parameters ImageJ could use the default constructor when the Plugin is loaded. After creating the constructor with parameters the default constructor is no longer present so ImageJ cannot instantiate the plugins and hence throw the error.

Adding default constructors to the classes will solve the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.