ConnectionRequest问题

时间:2017-05-22 06:52:36

标签: codenameone

我在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"));
    }
}

1 个答案:

答案 0 :(得分:1)

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

当处理对话框时,它会返回上一个表格,即显示对话框之前显示的表格。