获取图像名称CodeNameOne

时间:2017-04-27 03:22:13

标签: java codenameone

我想从数据库中获取对象列表 我是100%,我检索数据,但列表,所以我的PHP代码似乎是好的

    public ArrayList<Categorie> getListCategorie() {
     ArrayList<Categorie> listcategories = new ArrayList<>();


    ConnectionRequest con2 = new ConnectionRequest();
    con2.setUrl("http://localhost/pidev2017/selectcategorie.php");
    con2.addResponseListener(new ActionListener<NetworkEvent>() {
        @Override
        public void actionPerformed(NetworkEvent evt) {
        try {
        JSONParser j = new JSONParser();
        Map<String, Object> catefories = j.parseJSON(new CharArrayReader(new String(con2.getResponseData()).toCharArray()));
        List<Map<String, Object>> list = (List<Map<String, Object>>) catefories.get("Categorie");
        for (Map<String, Object> obj : list) {
            Categorie categorie = new Categorie();
            categorie.setId(Integer.parseInt(obj.get("id").toString()));
            categorie.setNomCategorie(obj.get("nomCategorie").toString());
            listcategories.add(categorie);
        }
    } catch (IOException ex) {
    }
        }

    });
    NetworkManager.getInstance().addToQueue(con2);
    return listcategories;
}

当我想获取我的结果“listcategories”时,我发现它是空的

1 个答案:

答案 0 :(得分:2)

更改

NetworkManager.getInstance().addToQueue(con2);

NetworkManager.getInstance().addToQueueAndWait(con2);

您可能在获取数据之前尝试获取结果。