gpt4 book ai didi

java - 这个错误是什么意思 : The method. ..is not applicable for the arguments

转载 作者:行者123 更新时间:2023-11-29 05:54:27 25 4
gpt4 key购买 nike

我是新手,我不明白这个错误是什么意思。

我试过谷歌搜索,但无法理解我所发现的内容。

我需要与 API 交互以将票证发布到远程服务器,并且我从我正在学习的教程中获得了这段代码。

在这段代码中我遇到了这个错误:

The method postToRemoteServer(String) in the type HelpDeskTestService is not applicable for the arguments (String, new AsyncCallback(){})

sendButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
HelpDeskTestService.postToRemoteServer(
"http://xx.xx.xx.xx/sdpapi/request/",
new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Failure getting XML through proxy");
}

@Override
public void onSuccess(String result) {
processXML(result);
}
});
}
});

这是来自同步接口(interface)的代码:

public String postToRemoteServer(final String serviceUrl)
throws HelpDeskTestException;

这是异步接口(interface)的代码:

void postToRemoteServer(
final String serviceUrl,
AsyncCallback<String> callback);

最后,这是实现类的代码:

@Override
public String postToRemoteServer(String serviceUrl)
throws HelpDeskTestException {

try {
//dividing url into host: http://some.server
//path: a/path/in/it
//and parameters: this=that&those=others

int hostStart= serviceUrl.indexOf("//");

int pathStart= serviceUrl.substring(hostStart + 2).indexOf("/");

int parameterStart= serviceUrl.substring(hostStart + 2 + pathStart).indexOf("?");

final String serverHost= serviceUrl.substring(0, hostStart + pathStart + 2);

final String serverPath= serviceUrl.substring(hostStart + 3,
hostStart + pathStart + 2 + parameterStart);

final String serverParameters= serviceUrl.substring(hostStart + pathStart + 3 + parameterStart);

final URL url = new URL(serverHost);

final URLConnection connection= url.openConnection();
connection.setDoOutput(true);

final OutputStreamWriter out= new OutputStreamWriter(connection.getOutputStream());

final BufferedReader in= new BufferedReader(new InputStreamReader(
connection.getInputStream()));

out.write("POST " + serverPath + "\r\n");
out.write("Host: " + serverHost + "\r\n");
out.write("Accept-Encoding: identity\r\n");
out.write("Connection: close\r\n");
out.write("Content-Type: application/x-www-form-urlencoded\r\n");
out.write("Content-Length: " + serverParameters.length() + "\r\n\r\n" +
serverParameters + "\r\n");


String result = "";
String inputLine;

while ((inputLine=in.readLine()) != null) {
result+= inputLine;
}

in.close();
out.close();

return result;

} catch (final Exception e) {
throw new HelpDeskTestException();

}

我们将不胜感激。

最佳答案

调用服务时需要使用异步接口(interface)。您可以使用 GWT.create() 创建它的一个实例。假设您的异步接口(interface)称为“HelpDeskTestServiceAsync”,您将执行如下操作:

HelpDeskTestServiceAsync asyncService = GWT.create(HelpDeskTestService.class);

asyncService.postToRemoteServer(
"http://xx.xx.xx.xx/sdpapi/request/",
new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Failure getting XML through proxy");
}

@Override
public void onSuccess(String result) {
processXML(result);
}
});

关于java - 这个错误是什么意思 : The method. ..is not applicable for the arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12711225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com