java - 找不到合适的构造函数 - (实际参数列表和形式参数列表的长度不同)

标签 java maven

我是java新手,所以如果答案很明显,请原谅。我的任务是将 java 项目转换为 Maven,但遇到了以下编译错误。

no suitable constructor found for EtHttpException(java.lang.String,java.lang.String)

FWIW同样的错误发生在多个其他类中

基类

public class EtHttpException extends Exception {

private java.lang.String currentURL = null;
private java.lang.String status = null;
private java.lang.String request = null;

/**
  EtHttpException constructor comment.
*/

public EtHttpException(String status, String newCurrentURL,Exception e) {
    super(status);
    currentURL = newCurrentURL;
}

public EtHttpException(String status, String newCurrentURL, String newRequest,Exception e) {
    super(status);
    currentURL = newCurrentURL;
    request = newRequest;
}

public java.lang.String getCurrentURL() {
    return currentURL;
}

public java.lang.String getRequest() {
    return request;
}

}

此处发生错误

public class EtHttpsConnection {

private String sendRequest(String requestMessage, String currentURL)
    throws EtHttpException {

String responseMessage = null;
int size = 0;
int offset = 0;
int length = 400;
byte[] buffer = new byte[4096];

try {
    setRequest(requestMessage);

    responseMessage=connect(currentURL);

    trace(currentURL);
    trace(requestMessage);
    String postRequestMessage =
        transformMessageToPostFormat(requestMessage, currentURL);

    trace(postRequestMessage);

} catch (Exception e) {

    e.printStackTrace();
    String msg = e.toString();                  
    disconnect();
    throw new EtHttpException(msg, currentURL);
}
// return response
return responseMessage;

}

发生其他地点错误

no suitable constructor found for EtHttpException(java.lang.String,< nulltype >)

public class NoCurrentURLException extends EtHttpException {

public NoCurrentURLException() {

    super("No current URL was retrieved from URLList", null);

}
}

我相当确定我可以在一个地方进行更改来解决这些错误,有人可以提供任何见解吗?

最佳答案

no suitable constructor found for EtHttpException(java.lang.String,java.lang.String)

错误消息告诉您没有带有两个字符串的 EtHttpException 构造函数。如果您查看 EtHttpException,您将看到两个构造函数:一个需要两个字符串和一个 Exception;另一个需要两个构造函数。另一个需要三个字符串和一个异常。

您正在尝试使用两个字符串 - 没有与此签名匹配的构造函数。

要修复此问题,请将 EtHttpsConnection 类中引发异常的位置更改为:

throw new EtHttpException(msg, currentURL, e);

然后更改 NoCurrentURLException 类的构造函数以使用如下所示的内容:

super("No current URL was retrieved from URLList", null, null);

关于java - 找不到合适的构造函数 - (实际参数列表和形式参数列表的长度不同),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45922675/

相关文章:

java - 将电子表格数据复制到 Oracle 数据库

java - 创建一个 Ant 目标来运行 jar 中的 java 类

java - pom.xml 中是否可以有两个 mainClass 或者能够在同一个 pom.xml 中运行两个类?

java - Maven 构建所有子模块,甚至使用配置文件

java - 如何以编程方式创建具有注入(inject)属性的 bean 定义?

java - 通过 int 值设置枚举

java - Hive 2 JDBCPreparedStatement 抛出错误无法识别表达式规范中 '?' '<EOF>' '<EOF>' 附近的输入

java - Google Drive SDK - 客户 secret - 它有多 secret ?

maven - 当前目录中存在 pom.xml 时将键映射到命令?

eclipse - "Post-commit hook failed (exit code 1) with no output"- 这是什么意思?怎么修?