IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Problème d'affichage de résultat


Sujet :

Android

  1. #1
    Membre éclairé Avatar de Raptor92
    Homme Profil pro
    Directeur des opérations & Innovation
    Inscrit en
    Juin 2009
    Messages
    953
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 66
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Directeur des opérations & Innovation
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 953
    Points : 766
    Points
    766
    Par défaut Problème d'affichage de résultat
    Bonjour

    Malgré mes recherches, je n'arrive pas à comprendre pourquoi je n'arrive pas à afficher le résultat de ma requête mysql, je vois bien le résultat de ma requête mais mon manque d'expérience ne me permette pas de trouver la solution
    Pourriez-vous me guider svp
    Bien à vous

    Fichier PHP:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    <?php
        try {
            // connection to the database.
            #$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
            $bdd = new mysqli('localhost', 'user', 'mdp', 'bdd');
     
            // Execute SQL request on the database.
            $sql = "SELECT * FROM articles";
            $response = $bdd->query($sql);
    		//$output = $response->fetchAll(PDO::FETCH_ASSOC);
    	} catch (Exception $e) {
            die('Erreur : ' . $e->getMessage());
        }
     
        // Print JSON encode of the array.
     //   
    	$myArray = array();
    	while($row = $response->fetch_array(MYSQLI_ASSOC)) {
            $myArray[] = json_decode(json_encode($row));
    	}
    	$sortie=json_encode($myArray, JSON_UNESCAPED_SLASHES);
     
    	echo("'"); 
    	print($sortie);
    	echo("'");
    ?>

    Main Activity:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    <?php
        try {
            // connection to the database.
            #$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
            $bdd = new mysqli('localhost', 'root', 'root', 'simag_dev');
     
            // Execute SQL request on the database.
            $sql = "SELECT * FROM articles";
            $response = $bdd->query($sql);
    		//$output = $response->fetchAll(PDO::FETCH_ASSOC);
    	} catch (Exception $e) {
            die('Erreur : ' . $e->getMessage());
        }
     
        // Print JSON encode of the array.
     //   
    	$myArray = array();
    	while($row = $response->fetch_array(MYSQLI_ASSOC)) {
            $myArray[] = json_decode(json_encode($row));
    	}
    	$sortie=json_encode($myArray, JSON_UNESCAPED_SLASHES);
     
    	echo("'"); 
    	print($sortie);
    	echo("'");
    ?>

    Logcat:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    02-04 13:39:57.736 12500-12500/? I/zygote: Not late-enabling -Xcheck:jni (already on)
    02-04 13:39:57.840 12500-12500/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
    02-04 13:39:58.159 12500-12500/com.simag.www.projet_select W/ActivityThread: Application com.simag.www.projet_select is waiting for the debugger on port 8100...
    02-04 13:39:58.240 12500-12500/com.simag.www.projet_select I/System.out: Sending WAIT chunk
    02-04 13:39:58.658 12500-12507/com.simag.www.projet_select I/zygote: Debugger is active
    02-04 13:39:58.659 12500-12500/com.simag.www.projet_select I/System.out: Debugger has connected
    02-04 13:39:58.660 12500-12500/com.simag.www.projet_select I/System.out: waiting for debugger to settle...
    02-04 13:39:58.861 12500-12500/com.simag.www.projet_select I/System.out: waiting for debugger to settle...
    02-04 13:39:59.062 12500-12500/com.simag.www.projet_select I/System.out: waiting for debugger to settle...
    02-04 13:39:59.263 12500-12500/com.simag.www.projet_select I/System.out: waiting for debugger to settle...
    02-04 13:39:59.465 12500-12500/com.simag.www.projet_select I/System.out: waiting for debugger to settle...
    02-04 13:39:59.666 12500-12500/com.simag.www.projet_select I/System.out: waiting for debugger to settle...
    02-04 13:39:59.867 12500-12500/com.simag.www.projet_select I/System.out: waiting for debugger to settle...
    02-04 13:40:00.068 12500-12500/com.simag.www.projet_select I/System.out: waiting for debugger to settle...
    02-04 13:40:00.270 12500-12500/com.simag.www.projet_select I/System.out: debugger has settled (1412)
    02-04 13:40:00.365 12500-12500/com.simag.www.projet_select I/InstantRun: starting instant run server: is main process
    02-04 13:40:00.860 12500-12530/com.simag.www.projet_select D/OpenGLRenderer: HWUI GL Pipeline
    02-04 13:40:00.888 12500-12531/com.simag.www.projet_select D/NetworkSecurityConfig: No Network Security Config specified, using platform default
    02-04 13:40:00.995 12500-12530/com.simag.www.projet_select I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
    02-04 13:40:00.995 12500-12530/com.simag.www.projet_select I/OpenGLRenderer: Initialized EGL, version 1.4
    02-04 13:40:00.996 12500-12530/com.simag.www.projet_select D/OpenGLRenderer: Swap behavior 1
    02-04 13:40:00.997 12500-12530/com.simag.www.projet_select W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
    02-04 13:40:00.997 12500-12530/com.simag.www.projet_select D/OpenGLRenderer: Swap behavior 0
    02-04 13:40:01.017 12500-12530/com.simag.www.projet_select D/EGL_emulation: eglCreateContext: 0x953ea180: maj 2 min 0 rcv 2
    02-04 13:40:01.083 12500-12530/com.simag.www.projet_select D/EGL_emulation: eglMakeCurrent: 0x953ea180: ver 2 0 (tinfo 0xb01eda40)
    02-04 13:40:01.478 12500-12500/com.simag.www.projet_select I/Choreographer: Skipped 31 frames!  The application may be doing too much work on its main thread.
    02-04 13:40:01.492 12500-12530/com.simag.www.projet_select D/EGL_emulation: eglMakeCurrent: 0x953ea180: ver 2 0 (tinfo 0xb01eda40)
    02-04 13:40:01.576 12500-12530/com.simag.www.projet_select I/chatty: uid=10085(com.simag.www.projet_select) RenderThread identical 1 line
    02-04 13:40:01.717 12500-12530/com.simag.www.projet_select D/EGL_emulation: eglMakeCurrent: 0x953ea180: ver 2 0 (tinfo 0xb01eda40)
    02-04 13:40:01.782 12500-12530/com.simag.www.projet_select D/EGL_emulation: eglMakeCurrent: 0x953ea180: ver 2 0 (tinfo 0xb01eda40)
    02-04 13:40:01.818 12500-12500/com.simag.www.projet_select E/JSON*Parser: Erreur parsing data org.json.JSONException: Value [{"art_id":"1","art_ref":"SERV1","art_design":"Serveur restaurant","art_prix":"287","art_four":"DELL"},{"art_id":"2","art_ref":"MH33","art_design":"Routeur","art_prix":"185","art_four":"MERAKY"},{"art_id":"3","art_ref":"ECR10","art_design":"Ecran 10","art_prix":"56","art_four":"APLUS"},{"art_id":"4","art_ref":"ZONE1","art_design":"Deplacement Paris Intra","art_prix":"75","art_four":"AWADAC"},{"art_id":"5","art_ref":"ZONE2","art_design":"Deplacement IDF","art_prix":"105","art_four":"AWADAC"},{"art_id":"6","art_ref":"ZONE3","art_design":"Deplacement hors IDF","art_prix":"175","art_four":"AWADAC"}] of type java.lang.String cannot be converted to JSONArray
    02-04 13:40:01.868 12500-12530/com.simag.www.projet_select D/EGL_emulation: eglMakeCurrent: 0x953ea180: ver 2 0 (tinfo 0xb01eda40)
    Raptor92
    Dominique
    Aucune aide par MP, utilisez le forum.

    Mon guide du débutant pour apprendre à programmer en Java - N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java


  2. #2
    Modérateur
    Avatar de Hizin
    Homme Profil pro
    Développeur mobile
    Inscrit en
    Février 2010
    Messages
    2 180
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Développeur mobile

    Informations forums :
    Inscription : Février 2010
    Messages : 2 180
    Points : 5 072
    Points
    5 072
    Par défaut
    Bonjour !
    Il nous faudrait le code Java (petite erreur d'étourderie, tu as mis 2 fois le code Php) pour réellement te dire

    Les logs indiquent une JSONException, avec un message d'erreur indiquant un problème de parsing des données.
    Tu sembles attendre dans tes POJO une String alors que tu fournis un tableau d'objets.

    Nota : je me demande pourquoi l'autre sujet a été verrouillé oO

    EDIT : voici le code Java :

    Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    import android.app.ListActivity;
    import android.app.ProgressDialog;
    import android.content.Intent;
    import android.os.AsyncTask;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ArrayAdapter;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.TextView;
    import android.widget.Toast;
     
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
     
    import java.io.BufferedInputStream;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.HashMap;
     
    import static com.simag.www.projet_select.R.layout.item;
     
     
    public class MainActivity extends AppCompatActivity {
        //-- 10.0.2.2 -- Remplacer l'IP
        String UrlServeur ="http://192.168.x.xx/projet_dev/envoi.php";
        ProgressDialog pDialog;
        ArrayList<HashMap<String, String>> listArticle = new ArrayList<HashMap<String, String>>();
        ListView  lv;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
     
            lv=(ListView)findViewById(R.id.listView);
     
     
            lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    Toast.makeText(MainActivity.this,listArticle.get(i).get("ID").toString()+"   "+listArticle.get(i).get("Nom").toString()+"   " +
                                    ""+listArticle.get(i).get("Design").toString()+"   "+listArticle.get(i).get("Tarif").toString()+"   "+listArticle.get(i).get("Four").toString(), Toast.LENGTH_SHORT ).show();
                }
            });
     
     
            new   Webservice().execute(UrlServeur);
     
        }
     
        class Webservice extends AsyncTask<String , Void,String> {
     
            @Override
            protected void onPreExecute () {
     
                pDialog = new ProgressDialog(MainActivity.this);
                pDialog.setMessage("Connexion au serveur ..");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(false);
                pDialog.show();
            }
     
     
     
            @Override
            protected String doInBackground(String... strings) {
                StringBuilder result = new StringBuilder();
                try {
     
                    HttpURLConnection conn;
     
                    URL url = new URL(strings[0]);
                    conn = (HttpURLConnection) url.openConnection();
     
                    conn.setDoInput(true);
                    conn.setRequestMethod("POST");
     
                    conn.setRequestProperty("Accept-Charset", "UTF-8");
     
                    conn.setConnectTimeout(1000);
     
                    conn.connect();
     
                    InputStream in = new BufferedInputStream(conn.getInputStream());
                    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
     
                    String line;
                    while ((line = reader.readLine()) != null) {
                        result.append(line);
                    }
                    conn.disconnect();
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
                return  result.toString();
            }
            @Override
            protected void  onPostExecute (String  JSON_Reponse ) {
                pDialog.dismiss();
                JSONObject jObj=null ;
                JSONArray  jArr =null;
     
                // try parse the string to a JSON object
                try {
                    jArr = new JSONArray(JSON_Reponse.toString());
     
                    for (int x=0 ;x<jArr.length();x++ ) {
     
                        jObj =jArr.getJSONObject(x) ;
                        String id=jObj.getString("id") ;
                        String nom=jObj.getString("Nom") ;
                        String design=jObj.getString("Design") ;
                        String tarif=jObj.getString("Tarif") ;
                        String four=jObj.getString("Four") ;
                        HashMap<String,String> map =new HashMap<>();
                        map.put("ID",id);
                        map.put("Nom",nom);
                        map.put("Design",design);
                        map.put("Tarif",tarif);
                        map.put("Four",four);
                        listArticle.add(map) ;
                    }
     
     
                } catch (JSONException e) {
                    Log.e("JSON Parser", "Error parsing data " + e.toString());
                }
     
                ListAdapter adapter = new SimpleAdapter(
                        MainActivity.this, listArticle,
                        R.layout.item, new String[] { "ID",
                        "Nom","Design","Tarif","Four"},
                        new int[] { R.id.id, R.id.nom, R.id.design, R.id.tarif, R.id.four });
                lv.setAdapter(adapter);
     
            }
     
        }
     
    }

    Première chose : pour tes logs.e, passe directement l'exception en tant que troisième paramètre de la méthode. Cela permet d'avoir toute l'exception, et de ne pas masquer les morceaux souvent intéressant qui sont dans la stacktrace.

    Ton code semble me confirmer que tu as un souci sur le traitement de tes données : tu requêtes une String alors que les données derrières sont sous forme de tableau
    C'est Android, PAS Androïd, ou Androïde didiou !
    Le premier est un OS, le second est la mauvaise orthographe du troisième, un mot français désignant un robot à forme humaine.

    Membre du comité contre la phrase "ça marche PAS" en titre et/ou explication de problème.

    N'oubliez pas de consulter les FAQ Android et les cours et tutoriels Android

  3. #3
    Membre éclairé Avatar de Raptor92
    Homme Profil pro
    Directeur des opérations & Innovation
    Inscrit en
    Juin 2009
    Messages
    953
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 66
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Directeur des opérations & Innovation
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 953
    Points : 766
    Points
    766
    Par défaut
    Bonjour

    Oups, voici le code java
    Merci beaucoup

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    import android.app.ProgressDialog;
    import android.os.AsyncTask;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.Toast;
     
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
     
    import java.io.BufferedInputStream;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.HashMap;
     
     
    public class MainActivity extends AppCompatActivity {
        //-- 10.0.2.2 -- Remplacer l'IP
        String UrlServeur = "http://192.168.1.16/projet_dev/envoi.php";
        ProgressDialog pDialog;
        ArrayList <HashMap <String, String>> listArticle = new ArrayList <HashMap <String, String>>();
        ListView lv;
     
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
     
            lv = ( ListView ) findViewById(R.id.listView);
     
     
            lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView <?> adapterView, View view, int i, long l) {
                    Toast.makeText(MainActivity.this, listArticle.get(i).get("id").toString() + "   " + listArticle.get(i).get("Nom").toString() + "   " + "" + listArticle.get(i).get("Design").toString() + "   " + listArticle.get(i).get("Tarif").toString() + "   " + listArticle.get(i).get("Four").toString(), Toast.LENGTH_SHORT).show();
                }
            });
     
     
            new Webservice().execute(UrlServeur);
     
        }
     
        class Webservice extends AsyncTask <String, Void, String> {
     
            @Override
            protected void onPreExecute() {
     
                pDialog = new ProgressDialog(MainActivity.this);
                pDialog.setMessage("Connexion au serveur ..");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(false);
                pDialog.show();
            }
     
     
            @Override
            protected String doInBackground(String... strings) {
                StringBuilder result = new StringBuilder();
                try {
     
                    HttpURLConnection conn;
     
                    URL url = new URL(strings[0]);
                    conn = ( HttpURLConnection ) url.openConnection();
     
                    conn.setDoInput(true);
                    conn.setRequestMethod("POST");
     
                    conn.setRequestProperty("Accept-Charset", "UTF-8");
     
                    conn.setConnectTimeout(1000);
     
                    conn.connect();
     
                    InputStream in = new BufferedInputStream(conn.getInputStream());
                    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
     
                    String line;
                    while ((line = reader.readLine()) != null) {
                        result.append(line);
                    }
                    conn.disconnect();
                } catch (IOException e) {
                    e.printStackTrace();
                    Log.e("JSON Parser", "Erreur connection " + e.toString());
                }
                return result.toString();
            }
     
            @Override
            protected void onPostExecute(String JSON_Reponse) {
                pDialog.dismiss();
                JSONObject jObj = null;
                JSONArray jArr = null;
     
                // try parse the string to a JSON object
                try {
                    jArr = new JSONArray(JSON_Reponse.toString());
     
                    for (int x = 0; x < jArr.length(); x++) {
     
                        jObj = jArr.getJSONObject(x);
                        String art_id = jObj.getString("id");
                        String art_ref = jObj.getString("Nom");
                        String art_design = jObj.getString("Design");
                        String art_prix = jObj.getString("Tarif");
                        String art_four = jObj.getString("Four");
                        HashMap <String, String> map = new HashMap <>();
                        map.put("id", art_id);
                        map.put("Nom", art_ref);
                        map.put("Design", art_design);
                        map.put("Tarif", art_prix);
                        map.put("Four", art_four);
                        listArticle.add(map);
                    }
     
     
                } catch (JSONException e) {
                    Log.e("JSON Parser", "Error parsing data " + e.toString());
                }
                /**
                 * Updating parsed JSON data into ListView
                 * */
     
                ListAdapter adapter = new SimpleAdapter(
                        MainActivity.this, listArticle,
                        R.layout.item, new String[] {"id", "Nom", "Design", "Tarif", "Four"},
                        new int[]{R.id.id, R.id.nom, R.id.design, R.id.tarif, R.id.four});
                // updating listview
                lv.setAdapter(adapter);
     
            }
     
        }
     
    }
    Raptor92
    Dominique
    Aucune aide par MP, utilisez le forum.

    Mon guide du débutant pour apprendre à programmer en Java - N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java


  4. #4
    Membre éclairé Avatar de Raptor92
    Homme Profil pro
    Directeur des opérations & Innovation
    Inscrit en
    Juin 2009
    Messages
    953
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 66
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Directeur des opérations & Innovation
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 953
    Points : 766
    Points
    766
    Par défaut
    Help please
    Raptor92
    Dominique
    Aucune aide par MP, utilisez le forum.

    Mon guide du débutant pour apprendre à programmer en Java - N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java


  5. #5
    Membre éclairé Avatar de Raptor92
    Homme Profil pro
    Directeur des opérations & Innovation
    Inscrit en
    Juin 2009
    Messages
    953
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 66
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Directeur des opérations & Innovation
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 953
    Points : 766
    Points
    766
    Par défaut
    Bonsoir

    J'ai l'impression que mon problème est ici

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
            protected void onPostExecute(String JSON_Reponse) {
                pDialog.dismiss();
                JSONObject jObj = null;
                JSONArray jArr = null;
     
                // try parse the string to a JSON object
                try {
                    jArr = new JSONArray(JSON_Reponse.toString());
     
                    for (int x = 0; x < jArr.length(); x++) {
     
                        jObj = jArr.getJSONObject(x);
                        String art_id = jObj.getString("id");
                        String art_ref = jObj.getString("Nom");
                        String art_design = jObj.getString("Design");
                        String art_prix = jObj.getString("Tarif");
                        String art_four = jObj.getString("Four");
                        HashMap <String, String> map = new HashMap <>();
                        map.put("id", art_id);
                        map.put("Nom", art_ref);
                        map.put("Design", art_design);
                        map.put("Tarif", art_prix);
                        map.put("Four", art_four);
                        listArticle.add(map);
    Mais je ne comprends pas comment le modifier, merci pour votre aide
    Bien à vous
    Raptor92
    Dominique
    Aucune aide par MP, utilisez le forum.

    Mon guide du débutant pour apprendre à programmer en Java - N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java


  6. #6
    Modérateur
    Avatar de Hizin
    Homme Profil pro
    Développeur mobile
    Inscrit en
    Février 2010
    Messages
    2 180
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Développeur mobile

    Informations forums :
    Inscription : Février 2010
    Messages : 2 180
    Points : 5 072
    Points
    5 072
    Par défaut
    Vu qu'il y a eu pas mal d'edit, j'imagine que tu n'as pas vu cette partie :
    Première chose : pour tes logs.e, passe directement l'exception en tant que troisième paramètre de la méthode. Cela permet d'avoir toute l'exception, et de ne pas masquer les morceaux souvent intéressant qui sont dans la stacktrace.

    Ton code semble me confirmer que tu as un souci sur le traitement de tes données : tu requêtes une String alors que les données derrières sont sous forme de tableau
    Il faut que les données que tu demandes correspondent à la structure du json.
    En général, je crée mes POJO et j'utilise GSON pour ça. Ca me permet d'éviter de me prendre la tête.
    C'est Android, PAS Androïd, ou Androïde didiou !
    Le premier est un OS, le second est la mauvaise orthographe du troisième, un mot français désignant un robot à forme humaine.

    Membre du comité contre la phrase "ça marche PAS" en titre et/ou explication de problème.

    N'oubliez pas de consulter les FAQ Android et les cours et tutoriels Android

  7. #7
    Membre éclairé Avatar de Raptor92
    Homme Profil pro
    Directeur des opérations & Innovation
    Inscrit en
    Juin 2009
    Messages
    953
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 66
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Directeur des opérations & Innovation
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 953
    Points : 766
    Points
    766
    Par défaut
    Bonjour

    Pourriez-vous me conseiller un bon tuto car j'ai du mal à comprendre
    Bien à vous
    Raptor92
    Dominique
    Aucune aide par MP, utilisez le forum.

    Mon guide du débutant pour apprendre à programmer en Java - N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java


  8. #8
    Modérateur
    Avatar de Hizin
    Homme Profil pro
    Développeur mobile
    Inscrit en
    Février 2010
    Messages
    2 180
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Développeur mobile

    Informations forums :
    Inscription : Février 2010
    Messages : 2 180
    Points : 5 072
    Points
    5 072
    Par défaut
    Avec GSon, en voici un : https://github.com/google/gson/blob/master/UserGuide.md

    C'est en général ce que j'utilise pour la sérialisation et désérialisation sur Android. Il faut pouvoir imaginer la projection de son JSON en objet. Hormis ça, c'est simple d'utilisation (et au pire, si on a du mal à faire la projection, il est possible d'y aller en s'aidant des exceptions).
    C'est Android, PAS Androïd, ou Androïde didiou !
    Le premier est un OS, le second est la mauvaise orthographe du troisième, un mot français désignant un robot à forme humaine.

    Membre du comité contre la phrase "ça marche PAS" en titre et/ou explication de problème.

    N'oubliez pas de consulter les FAQ Android et les cours et tutoriels Android

  9. #9
    Modérateur
    Avatar de MasterMbg
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2011
    Messages
    719
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Kinshasa

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2011
    Messages : 719
    Points : 1 493
    Points
    1 493
    Par défaut
    Salut,

    Comme Hizin t'a dit plus haut, tu as un problème de parsing de données en json. La chaîne de caractères que le serveur envoie n'est valide pour être parsé en jsonArray. Tu reçois bien le résultat comme le montre cette exception
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     02 - 04 13 :40 :01.818 12500- 12500/com.simag.www.projet_select E/JSON*Parser: Erreur parsing data org.json.JSONException: Value [{ "art_id" :"1" ,"art_ref" :"SERV1" , "art_design" :"Serveur restaurant" , "art_prix" : "287" ,"art_four" : "DELL" },{ "art_id" :"2" ,"art_ref" :"MH33" , "art_design" :"Routeur" , "art_prix" : "185" ,"art_four" : "MERAKY" },{ "art_id" :"3" , "art_ref" : "ECR10" ,"art_design" : "Ecran 10" ,"art_prix" :"56" ,"art_four" :"APLUS" },{ "art_id" :"4" , "art_ref" : "ZONE1" ,"art_design" : "Deplacement Paris Intra" , "art_prix" : "75" , "art_four" :"AWADAC" },{ "art_id" : "5" ,"art_ref" :"ZONE2" ,"art_design" : "Deplacement IDF" , "art_prix" :"105" , "art_four" : "AWADAC" },{ "art_id" :"6" , "art_ref" : "ZONE3" ,"art_design" : "Deplacement hors IDF" ,"art_prix" :"175" ,"art_four" :"AWADAC" }] of type java.lang.String cannot be converted to JSONArray

    Christian Djo,
    Plus tu apprends sérieusement, plus tu te rapproches d'un savoir noble. Une chose est certaine, les difficultés ne s'écarteront de ton chemin...

    Tu es nouveau dans le développement Android, la page des COURS est là pour te faciliter la vie
    Tu peux trouver la réponse à ta question dans la FAQ
    Retrouvez mon tutoriel sur la consommation des services web SOAP
    Pense à voter positivement en appuyant sur en bas à droite de la réponse qui t'a donné une piste de solution.

Discussions similaires

  1. Problème d'affichage de résultat
    Par tunis71187 dans le forum Reports
    Réponses: 2
    Dernier message: 21/02/2011, 08h55
  2. [MySQL] Petit problème d'affichage de résultats
    Par lukyVJ dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 27/01/2011, 11h24
  3. [PHP 4] Problème d'affichage de résultat
    Par fraisa1985 dans le forum Langage
    Réponses: 1
    Dernier message: 15/06/2009, 19h16
  4. problème d'affichage du résultat dans une classe qui utilise SNMP
    Par ramzouni dans le forum Débuter avec Java
    Réponses: 0
    Dernier message: 22/05/2009, 01h26
  5. Problème d'affichage du résultat
    Par cirtey dans le forum C
    Réponses: 6
    Dernier message: 24/02/2007, 19h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo