0

First, I am very new to Java and my programming in general is rusty. So I might have missed something very simple.

The error:

cannot find symbol
symbol  : method setMethod(java.lang.String)
location: class ij.plugin.Thresholder
        Thresholder.setMethod("Mean");

Some code snippets: This part is third party code. I would like to avoid modifying this as much as possible

public class Thresholder implements PlugIn, Measurements, ItemListener {
    private static String staticMethod = methods[0];

    public static void setMethod(String method) {
        staticMethod = method;
    }
}

My code (well, some relevant parts)

    import ij.plugin.Thresholder;
    public class CASA_ implements PlugInFilter,Measurements  {
    public void run(ImageProcessor ip) {
        track(imp, minSize, maxSize, maxVelocity);
    }

    public void track(ImagePlus imp, float minSize, float maxSize, float maxVelocity) {
        Thresholder.setMethod("Mean");         <-- This is the line the compiler hates
    }
}

Why is the compiler looking for a setMethod method with a return of something other than void?

Thanks

0

2 Answers 2

1

You can't call a method in a class declaration block. You can either do it in the constructor or in another method (that then has to be explicitly called on that class).

Sign up to request clarification or add additional context in comments.

Comments

0

As Makoto correctly states, you can't call Thresholder.setMethod("Mean") in the class declaration.

In a class implementing PlugInFilter, you have to define a run(ImageProcessor ip) and a setup(String arg, ImagePlus imp) method, so why don't you set the thresholding method during setup of your plugin filter:

import ij.IJ;
import ij.ImagePlus;
import ij.measure.Measurements;
import ij.plugin.Thresholder;
import ij.plugin.filter.PlugInFilter;
import ij.process.ImageProcessor;

public class CASA_ implements PlugInFilter,Measurements  {
    // define instance variables:
    ImagePlus imp;

    /**
     * implement interface methods
     */
    public int setup(String arg, ImagePlus imp) {
        this.imp = imp;
        Thresholder.setMethod("Mean");
        IJ.log("Setup done.");
        return DOES_ALL;
    }

    public void run(ImageProcessor ip) {
        // do your processing here
    }
}

Have a look at the ImageJ plugin writing tutorial or at Fiji's script editor and its templates (Templates > Java > Bare PlugInFilter) as a starting point.

3 Comments

You were correct in telling me about not being able to call a method in a class declaration, I actually did not know I can't do that. However, that was not the problem. I still get the same error.
The code above works for me without errors. I just edited my answer to include all the necessary imports. You can try the code by opening File > New > Script in Fiji, pasting the code, switching to Language > Java, and clicking on Run.
This works with the newest version of ImageJ (1.47q). I was trying to run it with 1.46 earlier.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.