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

Collection et Stream Java Discussion :

remplir un tableau à deux dimensions depuis une base de donnée


Sujet :

Collection et Stream Java

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2015
    Messages
    136
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2015
    Messages : 136
    Points : 52
    Points
    52
    Par défaut remplir un tableau à deux dimensions depuis une base de donnée
    bonsoir a tous !
    j'essaye de remplir un tableaux a deux dimension mais je sais pas comment faire ! j'ai pu récupérer les donnée depuis ma base
    longitude et latitude
    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
    StringRequest stringRequest = new StringRequest(Request.Method.POST, AppConfig.URL_Marker,
                        new Response.Listener<String>() {
     
     
                            @Override
                            public void onResponse(String response) {
     
                                try {
     
                                    JSONObject jsonObj = new JSONObject(response);
                                    JSONArray jsonArray = jsonObj.getJSONArray("markers");
     
     
                                    for (int i = 0; i < jsonArray.length(); i++) {
                                        jresponse = jsonArray.getJSONObject(i);
                                        latitude = Double.parseDouble(jresponse.getString("lat"));
                                        longitude = Double.parseDouble(jresponse.getString("lng"));
     
     
                                            mMap.addMarker(new MarkerOptions()
                                                .position(new LatLng(latitude,longitude))
                                                .icon(BitmapDescriptorFactory.fromResource(R.drawable.tram_48))
                                                .draggable(true));
     
                                    }
     
     
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                //pDialog.dismiss();
     
                            }
     
                        },

  2. #2
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 074
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 074
    Points : 7 978
    Points
    7 978
    Par défaut
    Je ne vois pas de tableau définit quelque part, c'est normal ?

    Sinon tu peux lire la FAQ sur comment on joue avec des tableaux/array
    (Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)

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

  3. #3
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2015
    Messages
    136
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2015
    Messages : 136
    Points : 52
    Points
    52
    Par défaut
    Citation Envoyé par wax78 Voir le message
    Je ne vois pas de tableau définit quelque part, c'est normal ?
    je vais le définir Localement
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
            double [][] StationTram = new double [25][2];
    maintenant je vais comment pour le remplir ligne par ligne ? la 1ere ligne doit contenir latitude pour la 1ere colonnes et longitude pour la 2eme

  4. #4
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 074
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 074
    Points : 7 978
    Points
    7 978
    Par défaut
    Prends la peine de lire la FAQ la réponse s'y trouve.
    (Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)

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

  5. #5
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2015
    Messages
    136
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2015
    Messages : 136
    Points : 52
    Points
    52
    Par défaut
    Citation Envoyé par wax78 Voir le message
    Prends la peine de lire la FAQ la réponse s'y trouve.
    Voila ce que j'ai fait , seulement y a une petite erreur ! il remplis chque Lat et Lng 25 fois pour la 1ere ligne de ma table (base de donnée) ainsi de suite
    ou je me suis trempé ?
    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
     
                                    for (int i = 0; i < jsonArray.length(); i++) {
                                        jresponse = jsonArray.getJSONObject(i);
                                        latitude = Double.parseDouble(jresponse.getString("lat"));
                                        longitude = Double.parseDouble(jresponse.getString("lng"));
     
     
                                        double [][] StationTram1 = new double [25][2];
     
     
                                        for(double[] point2 : StationTram1) {
                                            point2[0] = Double.parseDouble(jresponse.getString("lat"));;
                                            point2[1] = Double.parseDouble(jresponse.getString("lng"));
     
                                                Log.i("Longitude", String.valueOf(point2[0]));
                                                Log.i("Latitude", String.valueOf(point2[1]));
                                        }

  6. #6
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 074
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 074
    Points : 7 978
    Points
    7 978
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
        	 double [][] StationTram1 = new double [jsonArray.length()][2];
     
             for (int i = 0; i < jsonArray.length(); i++) {
                 jresponse = jsonArray.getJSONObject(i);
                 StationTram1[i][0]=Double.parseDouble(jresponse.getString("lat"));
                 StationTram1[i][1]=Double.parseDouble(jresponse.getString("lng"));
             }
    (Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)

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

  7. #7
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2015
    Messages
    136
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2015
    Messages : 136
    Points : 52
    Points
    52
    Par défaut
    ça marche pas !
    j'ai declaré le tabelaux globalement
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    double [][] StationTram1 = new double [25][2];
    et je l'ai remplie comme tu ma indiquer
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     for (int i = 0; i < jsonArray.length(); i++) {
                                    jresponse = jsonArray.getJSONObject(i);
                                    latitude = Double.parseDouble(jresponse.getString("lat"));
                                    longitude = Double.parseDouble(jresponse.getString("lng"));
                                    for(int j=0; j<StationTram1.length;j++) {
                                        StationTram1[j][0] = Double.parseDouble(jresponse.getString("lat"));
                                        StationTram1[j][1] = Double.parseDouble(jresponse.getString("lng"));
     
                                    }
    seulement lorsque je veux calculer la distance ça marche pas

    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
      for(double[] point : StationTram1) { 
     
                LatLng to = new LatLng(point[0], point[1]);
                //Calculating the distance in meters
                int distanceLambda = (int) SphericalUtil.computeDistanceBetween(from, to);
     
     
     
               if (distanceLambda < distance) { // cette distance est donc plus petite que la plus petite distance déjà trouvée
                    distance = distanceLambda;
                    Latitude1 = point[0];
                    Longitude1 = point[1];
     
                }
     
            }
    pourtant si je remplie le tableaux manuellement ça marche
    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
     double [][] StationTram = new double [25][2];
     
            //Station Le Rocher
            StationTram [0][0] = 35.2236078 ;
            StationTram [0][1] = -0.6092131;
     
            //Station Quatres Horloges
            StationTram [1][0] =35.1907590 ;
            StationTram [1][1] =-0.6340827 ;
            //Station Petit Vichy
            StationTram [2][0] = 35.1914282;
            StationTram [2][1] = -0.6292730;
            //Station Cascade
            StationTram [3][0] = 35.2102234 ;
            StationTram [3][1] = -0.6292730 ;
            //Station Gare Routière Est
            StationTram [4][0] =35.2128532 ;
            StationTram [4][1] =-0.6139107 ;
            //Station Cité Aadl Ben Hamouda
            StationTram [5][0] = 35.2201147;
            StationTram [5][1] = -0.6239696;
            //Station Benhamouda
            StationTram [6][0] =35.2174852;
            StationTram [6][1] = -0.6230255;
            //Station Gare Routière Nord
            StationTram [7][0] = 35.2231999 ;
            StationTram [7][1] = -0.6296344;
            //Station Gare Ferroviaire
            StationTram [8][0] = 35.2246723;
            StationTram [8][1] =-0.6305786;
            //Station Campus
            StationTram [9][0] = 35.2206756;
            StationTram [9][1] =-0.6423803;
            //Station Faculté de Droit
            StationTram [10][0] = 35.2163282;
            StationTram [10][1] =-0.6330677;
            //Station Sidi Djilali
            StationTram [11][0] = 35.2161752;
            StationTram [11][1] =-0.6243836;
            //Station Wiaam
            StationTram [12][0] = 35.2102847;
            StationTram [12][1] =-0.6272590;
            //Station Azzouz
            StationTram [13][0] = 35.2031314;
            StationTram [13][1] =-0.6254565;
            //Station H.Boumedienne
            StationTram [14][0] = 35.2011677;
            StationTram [14][1] =-0.6191050;
            //Station Sbyka
            StationTram [15][0] = 35.1946448;
            StationTram [15][1] =-0.6125390;
            //Station Matérnité
            StationTram [16][0] = 35.1927510;
            StationTram [16][1] =-0.6149852;
            //Station Sidi Yacine
            StationTram [17][0] = 35.1926107;
            StationTram [17][1] =-0.6187617;
            //Station Jardin
            StationTram [18][0] = 35.1904012;
            StationTram [18][1] =-0.6422793;
            //Station Gare Routière Sud
            StationTram [19][0] = 35.1859469;
            StationTram [19][1] =-0.6495749;
            //Station Rectorat
            StationTram [20][0] = 35.1788616;
            StationTram [20][1] =-0.6600892;
            //Station Institut Science Médicale
            StationTram [21][0] = 35.1798438;
            StationTram [21][1] =-0.6449401;
            //Station BD.Amara
            StationTram [22][0] =35.1802647;
     
            StationTram [22][1] =-0.6352412;
            //Station Cité 20 AOUT
            StationTram [23][0] = 35.1816327;
            StationTram [23][1] = -0.6267440;
            ////Station Mexique
            StationTram [24][0] = 35.2172748 ;
            StationTram [24][1] = -0.6394620;

  8. #8
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 074
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 074
    Points : 7 978
    Points
    7 978
    Par défaut
    Citation Envoyé par abbescr7 Voir le message
    ça marche pas !


    Citation Envoyé par abbescr7 Voir le message
    j'ai declaré le tabelaux globalement
    C'est mieux en effet de le declarer avant la boucle.

    et je l'ai remplie comme tu ma indiquer
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     for (int i = 0; i < jsonArray.length(); i++) {
                                    jresponse = jsonArray.getJSONObject(i);
                                    latitude = Double.parseDouble(jresponse.getString("lat"));
                                    longitude = Double.parseDouble(jresponse.getString("lng"));
                                    for(int j=0; j<StationTram1.length;j++) {
                                        StationTram1[j][0] = Double.parseDouble(jresponse.getString("lat"));
                                        StationTram1[j][1] = Double.parseDouble(jresponse.getString("lng"));
     
                                    }
    Ce n'est pas du tout le code que j'ai écrits. Mon code n'as pas 2 boucles imbriquées...
    (Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)

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

  9. #9
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2015
    Messages
    136
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2015
    Messages : 136
    Points : 52
    Points
    52
    Par défaut
    Citation Envoyé par wax78 Voir le message




    C'est mieux en effet de le declarer avant la boucle.
    oui mais si je le déclare avant la boucle
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     try {
     
                                JSONObject jsonObj = new JSONObject(response);
                                JSONArray jsonArray = jsonObj.getJSONArray("markers");
     
     
                                double [][] StationTram1 = new double [jsonArray.length()][2];
     
                                for (int i = 0; i < jsonArray.length(); i++) {
                                    jresponse = jsonArray.getJSONObject(i);
                                    StationTram1[i][0]=Double.parseDouble(jresponse.getString("lat"));
                                    StationTram1[i][1]=Double.parseDouble(jresponse.getString("lng"));
                                }
    Lorsque je veux calculé la distance

    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
     for(double[] point : StationTram1) { // si ton tableau de point c'est double[][] tableauDePoint
     
                LatLng to = new LatLng(point[0], point[1]);
                //Calculating the distance in meters
                int distanceLambda = (int) SphericalUtil.computeDistanceBetween(from, to);
     
     
     
               if (distanceLambda < distance) { // cette distance est donc plus petite que la plus petite distance déjà trouvée
                    distance = distanceLambda;
                    Latitude1 = point[0];
                    Longitude1 = point[1];
     
                }
     
            }
    j'ai une erreur : "Can't Resolve StationTram1"

Discussions similaires

  1. [C#] Remplir une textbox depuis une base de donnée
    Par Nicos6414 dans le forum Windows Forms
    Réponses: 1
    Dernier message: 11/04/2011, 12h03
  2. Réponses: 1
    Dernier message: 14/04/2010, 17h13
  3. Comment passer un tableau à deux dimensions dans une fonction
    Par Niko_de_bordo dans le forum Débuter
    Réponses: 2
    Dernier message: 02/07/2009, 15h15
  4. Passage de tableau à deux dimensions dans une session
    Par keumlebarbare dans le forum Servlets/JSP
    Réponses: 7
    Dernier message: 28/11/2006, 18h42

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