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

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 プラグイン作成チュートリアルまたはフィジーのスクリプト エディターとそのテンプレート ( [テンプレート] > [Java] > [ベアプラグインフィルター]) を参照してください。

于 2013-05-27T20:40:54.713 に答える