[英]Compiler error cannot find symbol - Java
首先,我對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方法?
謝謝
您不能在類聲明塊中調用方法。 您可以在構造函數中或在其他方法中執行此操作(然后必須在該類上顯式調用)。
如誠誠所言,您不能在類聲明中調用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插件編寫教程或斐濟的腳本編輯器及其模板( Templates> Java> Bare PlugInFilter )為起點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.