首先,我对 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 方法?
谢谢
最佳答案
不能在类声明 block 中调用方法。您可以在构造函数或另一个方法中执行此操作(然后必须在该类上显式调用该方法)。
关于java - 编译器错误找不到符号 - Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16778703/