If you are experiencing an issue please mention the full platform your 
issue applies to:
IDE: NetBeans
Simulator 

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/162dbb4a-994b-40c8-a3af-acab803b928f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package serviceImpl;

import com.codename1.io.CharArrayReader;
import com.codename1.io.ConnectionRequest;
import com.codename1.io.JSONParser;
import com.codename1.io.NetworkEvent;
import com.codename1.io.NetworkManager;
import com.codename1.ui.events.ActionListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import model.Membre;

/**
 *
 * @author wassim
 */
public class MembreService {

public Membre me ;
public Membre aux;
    public MembreService() {
    }

 

    public Membre getPubMember(int id) {
                           me  = new Membre();

        ConnectionRequest con = new ConnectionRequest();
        con.setUrl("http://localhost/piService/getUserById.php?userId="; + id);

        con.addResponseListener(new ActionListener<NetworkEvent>() {
            @Override
            public void actionPerformed(NetworkEvent evt) {
                try {

                    JSONParser j = new JSONParser();
                    Map<String, Object> users = j.parseJSON(new CharArrayReader(new String(con.getResponseData()).toCharArray()));
                    Map<String, Object> obj = (Map<String, Object>) users.get("users");
                    me.setId(Integer.parseInt(obj.get("id").toString()));
                    me.setUsername(obj.get("username").toString());
                    me.setEmail(obj.get("email").toString());
                    me.setAge(Integer.parseInt(obj.get("age").toString()));
                    me.setNom(obj.get("nom").toString());
                    me.setPrenom(obj.get("prenom").toString());
                    me.setProfil_pic(obj.get("profile_pic").toString());
                    aux = me;

                } catch (IOException ex) {
                    //Logger.getLogger(MembreService.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
        });
        //NetworkManager.getInstance().addToQueue(con);
        System.out.println(aux);
        return me;

    }

}

Reply via email to