【问题标题】:get the image name CodeNameOne获取图片名称 CodeNameOne
【发布时间】:2017-04-27 22:54:56
【问题描述】:

我想从数据库中获取对象列表 我是 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”时,我发现它是空的

【问题讨论】:

    标签: java codenameone


    【解决方案1】:

    改变

    NetworkManager.getInstance().addToQueue(con2);
    

    NetworkManager.getInstance().addToQueueAndWait(con2);
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-04
      • 2012-04-04
      • 2012-09-02
      • 2015-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多