![](/img/trans.png)
[英]Android Studio says “cannot resolve method” but method exists and compiles
[英]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"
。 問題是reportDone()
在接口和實現中都存在並編譯 class。我已確保給定的參數與方法簽名匹配。 我也嘗試過導入IReporter
和Reporter
,但這也沒有用。 此外,我在接口中創建了一個新方法,實現了它,並從ResponseInterceptor
調用了它,新方法工作得很好。 這讓我想到,如果我只是復制該方法並給它一個新名稱,以與reportDone()
相同的方式實現和調用它,那就行得通了。 它沒有。 如果重要的話,這些文件都在同一個目錄中。
這是ResponseInterceptor
中的方法調用:
Browser.getReporter().reportDone(String.format("Response: %s", responseCode),
String.format("StatusCode= %s :: URL= %s :: Header= %s :: Body= %s", statusCode, url, headers, responseBody));
這是它在IReporter
中的定義:
void reportDone(String stepName, String stepDescription);
這是它在Reporter
中的實現:
public void reportDone(String stepName, String stepDescription) {
report.updateTestLog(stepName, stepDescription, Status.DONE);
}
我找到了解決方案。 有兩個 IReporter 類。 我只需要將程序轉換為正確的 IReporter,就像這樣:
((automation.IReporter)Browser.getReporter().reportDone(String.format(...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.