0

首先,我对 Java 很陌生,而且我的编程总体上是生疏的。所以我可能错过了一些非常简单的事情。

错误:

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

一些代码片段:这部分是第三方代码。我想尽可能避免修改它

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

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

我的代码(嗯,一些相关部分)

    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
    }
}

为什么编译器要寻找一个返回 void 以外的东西的 setMethod 方法?

谢谢

4

2 回答 2

1

您不能在类声明块中调用方法。您可以在构造函数或其他方法中执行此操作(然后必须在该类上显式调用)。

于 2013-05-27T18:35:12.567 回答
0

正如 Makoto 正确指出的那样,您不能Thresholder.setMethod("Mean")在类声明中调用。

在实现的类PlugInFilter中,您必须定义一个run(ImageProcessor ip)和一个setup(String arg, ImagePlus imp)方法,那么为什么不在您的插件过滤器设置期间设置阈值方法:

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
    }
}

查看ImageJ 插件编写教程Fiji 的脚本编辑器及其模板 ( Templates > Java > Bare PlugInFilter ) 作为起点。

于 2013-05-27T20:40:54.713 回答