简体   繁体   English

无法解析调用 class 中的方法,但方法在接口和实现类中都存在(并编译)

[英]Cannot resolve method in calling class, but method exists (and compiles) in both the interface and implementation classes

I'm writing a suite of Selenium tests in Java. Part of the program relies on a class called ResponseInterceptor.java , which uses methods from both my IReporter.java interface and Reporter.java implementation class. I am getting a Cannot resolve method "reportDone" in "IReporter" error. I'm writing a suite of Selenium tests in Java. Part of the program relies on a class called ResponseInterceptor.java , which uses methods from both my IReporter.java interface and Reporter.java implementation class. I am getting a Cannot resolve method "reportDone" in "IReporter" The problem is that reportDone() exists, and compiles, in both the interface and the implementation class. I have made sure the given paramenters match the method signature.问题是reportDone()在接口和实现中都存在并编译 class。我已确保给定的参数与方法签名匹配。 I have also tried importing IReporter and Reporter , but this did not work either.我也尝试过导入IReporterReporter ,但这也没有用。 In addition, I created a new method in the interface, implemented it, and called it from ResponseInterceptor , and the new method works just fine.此外,我在接口中创建了一个新方法,实现了它,并从ResponseInterceptor调用了它,新方法工作得很好。 This made me think that if I just copied the method and gave it a new name, implementing and calling it the same way as reportDone() , that would work.这让我想到,如果我只是复制该方法并给它一个新名称,以与reportDone()相同的方式实现和调用它,那就行得通了。 It did not.它没有。 The files are all in the same directory, if that matters.如果重要的话,这些文件都在同一个目录中。

Here is the method call in ResponseInterceptor :这是ResponseInterceptor中的方法调用:

Browser.getReporter().reportDone(String.format("Response: %s", responseCode),
    String.format("StatusCode= %s :: URL= %s :: Header= %s :: Body= %s", statusCode, url, headers, responseBody));

Here is its definition in IReporter :这是它在IReporter中的定义:

void reportDone(String stepName, String stepDescription);

Here is its implementation in Reporter :这是它在Reporter中的实现:

public void reportDone(String stepName, String stepDescription) {
    report.updateTestLog(stepName, stepDescription, Status.DONE);
}

I found the solution.我找到了解决方案。 There were two IReporter classes.有两个 IReporter 类。 I simply had to cast the procedures to the correct IReporter, like so:我只需要将程序转换为正确的 IReporter,就像这样:

((automation.IReporter)Browser.getReporter().reportDone(String.format(...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM