【问题标题】:ConnectionRequest issue连接请求问题
【发布时间】:2017-05-23 11:36:30
【问题描述】:

我在 postResponse 中调用了“new NewForm(res).show()”,但尽管连接成功,但看不到特定的表单。我发现如果我注释掉'cr.setDisposeOnCompletion(d)',那么它工作正常。 但是如果发生任何异常等等,无限的进展就会无限运行。这是一个错误吗?它发生在我更新到新的 cn1 库更新之后。如果你想看这个项目,它在这里: https://drive.google.com/file/d/0B8ATnICIY2S8LUdta0F5NXYzamM/view?usp=sharing

Button checkButton = new Button("Check");
checkButton.addActionListener(e -> {
    ConnectionCheck cc = new ConnectionCheck(theme);
    cc.connectionCheckMethod();
});

ConnectionCheck 类

public class ConnectionCheck {

Resources res;
Dialog d;

public ConnectionCheck(Resources res) {
    this.res = res;
}

public void connectionCheckMethod() {
    ConnectionRequest cr = new ConnectionRequest() {

        @Override
        protected void readResponse(InputStream input) throws IOException {
            JSONParser jsonp = new JSONParser();
            Map<String, Object> parser = jsonp.parseJSON(new InputStreamReader(input));
            System.out.println("bibek " + parser);
        }

        @Override
        protected void postResponse() {
               new NewForm(res).show();
        //       d.dispose();
        }

        @Override
        protected void handleErrorResponseCode(int code, String message) {
            System.out.println("login ErrorResponseCode " + code + "msg: " + message);
        //    d.dispose();
        }

        @Override
        protected void handleException(Exception err) {
            System.out.println("login Exception " + err);
        //    d.dispose();
        }

        @Override
        protected void handleIOException(IOException err) {
            System.out.println("login IOException " + err);
         //   d.dispose();
        }

        @Override
        protected void handleRuntimeException(RuntimeException err) {
            System.out.println("login RuntimeException " + err);
        //    d.dispose();
        }
    };
    cr.setPost(true);
    cr.setUrl("http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo");
    cr.setTimeout(30000);
    cr.addRequestHeader("Accept", "application/json");
    InfiniteProgress ip = new InfiniteProgress();
    d = ip.showInifiniteBlocking();
    cr.setDisposeOnCompletion(d); //if this line is commented, the newForm is shown
    NetworkManager.getInstance().addToQueueAndWait(cr);
    }
}

NewForm 类

public class NewForm extends Form{

    public NewForm(Resources res){
        setTitle("new Form");
        add(new Label("new Form"));
    }
}

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    您需要在调用新表单的显示之前处理对话框。完成时处理将在连接完成时处理对话框,这有时是不可预测的。

    当一个对话框被释放时,它会返回到以前的形式,即在显示对话框之前显示的那个。

    【讨论】:

    • 我在 postResponse 方法中调用了新表单。 PostResponse() 应该在 connectionRequest 成功后调用(即在 postResponse 中的新表单之前调用完成时的处理),不是吗?上面的代码以前可以工作。我现在应该做什么改变?是否必须在 post response 方法和每个异常处理方法中手动处理对话框?
    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2018-10-24
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多