1

私はこれに不慣れで、このエラーが何を意味するのか理解できません。

グーグルを試しましたが、見つけたものがわかりません。

チケットをリモートサーバーに投稿するには、APIを操作する必要があります。このコードは、フォローしているチュートリアルから取得しました。

このコードブロックでは、次のエラーが発生します。

タイプHelpDeskTestServiceのメソッドpostToRemoteServer(String)は、引数には適用できません(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);
                        }
                    });
        }
    });

同期インターフェースからのコードは次のとおりです。

public String postToRemoteServer(final String serviceUrl)
    throws HelpDeskTestException;

非同期インターフェースのコードは次のとおりです。

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();

    }

どんな助けでもありがたいです。

4

3 に答える 3

3

サービスを呼び出すときは、非同期インターフェースを使用する必要があります。GWT.create()を使用してそのインスタンスを作成します。非同期インターフェースの名前が「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);
                    }
                });
于 2012-10-03T15:09:32.490 に答える
0

このエラーは、引数式の型がメソッドの仮パラメーターの型と一致しないことを意味します。

"タイプHelpDeskTestServiceのメソッドpostToRemoteServer(String)は、引数(String、new AsyncCallback(){})には適用できません。"

2つの引数を使用しようとしていると言っていますがpostToRemoteServer、1つの引数を取ると宣言されています。

これが発生している理由は完全には明らかではありませんが、静的メソッドを呼び出しているように見えます。その場合、インターフェイスは無効です。

あるいは、HelpDeskTestServiceが変数(tsk、tsk...コードスタイル違反...tsk、tsk)の場合、問題は変数の宣言された型である可能性があります。であると宣言した場合、言語は、 extendsを除いて、タイプ...Synchronousのすべてのメソッドを許可しません。AsynchronousSynchronousAsynchronous

于 2012-10-03T15:02:04.160 に答える
0

まさにその通り、StringとASyncCallbackタイプで呼び出します。文字列のみで呼び出す必要があります。使用法の詳細については、そのメソッドのAPIドキュメントまたは「HelpDeskTestService」クラスを参照してください。

于 2012-10-03T15:02:15.237 に答える