我是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/