cn1-尝试在空对象引用上调用虚拟方法'boolean java.util.ArrayList.add(java.lang.Object)'

时间:2018-11-18 06:15:26

标签: codenameone

我抛出一个错误,无法弄清楚它是怎么发生的。它不是一直发生,而是偶尔出现。引发的错误消息是“ Java.lang.nullPointerException:尝试在空对象引用上调用虚拟方法'boolean java.util.ArrayList.add(java.lang.Object)'”。我已经使用connectionRequest来解析json数据。当引发错误时,我检查了url是否存在问题,但它像往常一样提供了正确的json数据。尝试几次后,错误会自动解决。

if (!regNOField.getText().equals("") && !newPasswordField.getText().equals("")) {
    ArrayList<Map<String, String>> argumentsArrayList = new ArrayList<>();

    Map argumentMap1 = new HashMap();
    argumentMap1.put("argument", "reg_no");
    argumentMap1.put("value", regNOField.getText().trim());
    argumentsArrayList.add(argumentMap1);

    Map argumentMap2 = new HashMap();
    argumentMap2.put("argument", "token");
    argumentMap2.put("value", newPasswordField.getText().trim());
    argumentsArrayList.add(argumentMap2);

    CommonMethod.connectionMethod(res, true, url, "Verification", argumentsArrayList, true, null);
}

CommonMethod.connectionMethod:

public static void connectionMethod(Resources res, Boolean postBoolean, String urlString, String form, ArrayList<Map<String, String>> arguments,
        Boolean ipFlag, String extraData) {
    ConnectionRequest cr = new ConnectionRequest() {

        @Override
        protected void readResponse(InputStream input) throws IOException {
            JSONParser jp = new JSONParser();
            parser = jp.parseJSON(new InputStreamReader(input));
            response = null;
            if (parser != null && !parser.isEmpty()) {
                if (parser.get("status").equals("true")) {
                    message = (String) parser.get("data");
                    ToastBar.getInstance().setPosition(Component.TOP);
                    ToastBar.showErrorMessage(message, 5000);
                    if (form.equals("Verification")) {
                        if (d != null) {
                            d.dispose();
                        }
                        new LoginAndSignUp(res, message).show();
                    }  
                } 
            }
        }

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

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

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

        @Override
        protected void handleRuntimeException(RuntimeException err) {
            System.out.println("RuntimeException " + err);
        }
    };
    cr.setPost(postBoolean);
    cr.setUrl(urlString);
    cr.setTimeout(80000);
    if (arguments != null && !postBoolean.equals(false)) {
        for (Map<String, String> entrySet : arguments) {
            String argument1 = (String) entrySet.get("argument");
            String value1 = (String) entrySet.get("value");
            cr.addArgument(argument1, value1);
        }
    }
    InfiniteProgress ip = new InfiniteProgress();
    d = ip.showInifiniteBlocking();
    cr.setDisposeOnCompletion(d);
    cr.addRequestHeader("accept", "application/json");
    NetworkManager.getInstance().addToQueueAndWait(cr);
}

错误消息:

enter image description here

0 个答案:

没有答案