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 Studio Java Discussion :

Problème d'affichage de tableau avec Android Studio.


Sujet :

Android Studio Java

  1. #1
    Candidat au Club
    Homme Profil pro
    Stagiaire
    Inscrit en
    Mai 2017
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Stagiaire
    Secteur : Bâtiment

    Informations forums :
    Inscription : Mai 2017
    Messages : 9
    Points : 4
    Points
    4
    Par défaut Problème d'affichage de tableau avec Android Studio.
    Bonjour, comment allez vous ?
    Alors voila j'ai un petit problème avec mon code java sous android studio :
    je m'explique, j'essaye de créer un menu à partir d'un tableau, j'ai réussi vaguement à configurer les lignes, normalement tout est bon je compile, le build gradle se termine correctement, pas de messages d'erreurs mais seulement voila, lorsque je lance l'application avec l'émulateur elle se ferme toute seule et il n'y a aucun moyen de la relancer ...
    J'implore votre aide car je n'arrive pas à situer mon erreur ...
    Voici le code contenu dans le DummyContent :




    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
    package com.example.cegelec.cegelecvideo.dummy;
     
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import android.content.Context;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    import android.util.Log;
     
    /**
     * Helper class for providing sample content for user interfaces created by
     * Android template wizards.
     * <p>
     * TODO: Replace all uses of this class before publishing your app.
     */
     
    public class DummyContent {
        /**
         * An array of sample (dummy) items.
         */
        public static final List<DummyItem> ITEMS = new ArrayList<DummyItem>();
     
        /**
         * A map of sample (dummy) items, by ID.
         */
        public static final Map<String, DummyItem> ITEM_MAP = new HashMap<String, DummyItem>();
     
        private static final int COUNT = 4;
     
        public static final String MENU[] = {"MENU"};
     
        static{
     
     
            // Creation du tableau et de son contenu
            int tailleDeLaBoucle = 4;
            String[] MENU = new String[tailleDeLaBoucle];
            for (int i = 0; i < tailleDeLaBoucle; i++) {
                    MENU[0] = "PRESENTATION"; {
                    MENU[1] = "SUPERVISION";{
                    MENU[2] = "CAMERAS";{
                    MENU[3] = "CONTACTS";
                        }
                    }
                }
            }
     
            // Creation de l'affichage
            for (int i = 1; i <= COUNT; i++) {
                addItem(createDummyItem(i, MENU[i]));
            }
        }
     
        private static void addItem(DummyItem item) {
            ITEMS.add(item);
            ITEM_MAP.put(item.id, item);
        }
     
        // Fonction d'affichage
        private static DummyItem createDummyItem(int position, String MENU) {
            return new DummyItem(String.valueOf(position), String.valueOf(MENU), makeDetails(position));
            }
     
        private static String makeDetails(int position) {
            StringBuilder builder = new StringBuilder();
            builder.append("Details about Item: ").append(position);
            for (int i = 0; i < position; i++) {
                builder.append("\nMore details information here.");
            }
            return builder.toString();
        }
     
        /**
         * A dummy item representing a piece of content.
         */
        public static class DummyItem {
            public final String id;
            public final String content;
            public final String details;
     
            public DummyItem(String id, String content, String details) {
                this.id = id;
                this.content = content;
                this.details = details;
            }
     
            @Override
            public String toString() {
                return content;
            }
        }
    }

  2. #2
    Modérateur
    Avatar de grunk
    Homme Profil pro
    Lead dév - Architecte
    Inscrit en
    Août 2003
    Messages
    6 691
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Lead dév - Architecte
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2003
    Messages : 6 691
    Points : 20 222
    Points
    20 222
    Par défaut
    Quel est le message d'erreur dans le logcat ?
    Le debuggage ca commence par là. une appli qui plante sans erreur ca n'existe pas.

    Je sais pas à quoi doit servir ta boucle for mais dans l'état elle sert à rien :/
    Pry Framework php5 | N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #3
    Candidat au Club
    Homme Profil pro
    Stagiaire
    Inscrit en
    Mai 2017
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Stagiaire
    Secteur : Bâtiment

    Informations forums :
    Inscription : Mai 2017
    Messages : 9
    Points : 4
    Points
    4
    Par défaut
    Citation Envoyé par grunk Voir le message
    Quel est le message d'erreur dans le logcat ? :/
    Dans l'Event Log ? il me dit:"
    08:03 Can't bind to local 8601 for debugger

    08:04 Error running app: Unable to open debugger port (localhost:8616): java.io.IOException "

    Je ne comprend pas trop j'ai un peu honte...

  4. #4
    Modérateur
    Avatar de grunk
    Homme Profil pro
    Lead dév - Architecte
    Inscrit en
    Août 2003
    Messages
    6 691
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Lead dév - Architecte
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2003
    Messages : 6 691
    Points : 20 222
    Points
    20 222
    Par défaut
    Le log cat est disponible dans android studio via le raccourcis Alt+6 (ou via l'onglet Android monitor en bas de la fenêtre).
    Il faut que le bon appareil et la bonne application soit sélectionnées dans les listes déroulantes pour voir quelque chose d'intéressant.

    Si tu as un appareil avec une surcouche type samsung attends toi à voir énormément de bruit dans le logcat (filtrable).
    Pry Framework php5 | N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  5. #5
    Candidat au Club
    Homme Profil pro
    Stagiaire
    Inscrit en
    Mai 2017
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Stagiaire
    Secteur : Bâtiment

    Informations forums :
    Inscription : Mai 2017
    Messages : 9
    Points : 4
    Points
    4
    Par défaut le logcat
    j'ai trouvé le logcat, qui me dit les deux lignes suivantes : "
    05-09 06:05:36.091 1973-1973/android.ext.services W/art: Unexpected CPU variant for X86 using defaults: x86
    05-09 06:05:36.147 1973-1973/android.ext.services W/System: ClassLoader referenced unknown path: /system/priv-app/ExtServices/lib/x86"

    encore une fois je ne comprend pas trop..

  6. #6
    Modérateur
    Avatar de grunk
    Homme Profil pro
    Lead dév - Architecte
    Inscrit en
    Août 2003
    Messages
    6 691
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Lead dév - Architecte
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2003
    Messages : 6 691
    Points : 20 222
    Points
    20 222
    Par défaut
    Rien à voir avec ton application ce sont des logs système.

    Il faut que tu filtres sur ton application (avec tous les filtres disponible au dessus du logcat) et éventuellement uniquement sur les log de type Error (Debug par defaut)

    Donc pour résumer :
    1er filtre tu choisi ton appareil sur lequel tourne l'application
    2eme, tu choisis ton application
    3eme, Debug ou Error
    4eme : "Show only selected application"

    Il va de sois que l'application doit être lancée via android studio.
    Pry Framework php5 | N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  7. #7
    Candidat au Club
    Homme Profil pro
    Stagiaire
    Inscrit en
    Mai 2017
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Stagiaire
    Secteur : Bâtiment

    Informations forums :
    Inscription : Mai 2017
    Messages : 9
    Points : 4
    Points
    4
    Par défaut
    et maintenant voilà ce qu'il me dit, je comprend de moins en moins..:"

    05-09 12:28:36.858 3195-3195/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.cegelec.cegelecvideo, PID: 3195
    java.lang.ExceptionInInitializerError
    at com.example.cegelec.cegelecvideo.ItemVideoListActivity.setupRecyclerView(ItemVideoListActivity.java:70)
    at com.example.cegelec.cegelecvideo.ItemVideoListActivity.onCreate(ItemVideoListActivity.java:58)
    at android.app.Activity.performCreate(Activity.java:6679)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6119)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: length=4; index=4
    at com.example.cegelec.cegelecvideo.dummy.DummyContent.<clinit>(DummyContent.java:52)
    at com.example.cegelec.cegelecvideo.ItemVideoListActivity.setupRecyclerView(ItemVideoListActivity.java:70)*
    at com.example.cegelec.cegelecvideo.ItemVideoListActivity.onCreate(ItemVideoListActivity.java:58)*
    at android.app.Activity.performCreate(Activity.java:6679)*
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)*
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)*
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)*
    at android.app.ActivityThread.-wrap12(ActivityThread.java)*
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)*
    at android.os.Handler.dispatchMessage(Handler.java:102)*
    at android.os.Looper.loop(Looper.java:154)*
    at android.app.ActivityThread.main(ActivityThread.java:6119)*
    at java.lang.reflect.Method.invoke(Native Method)*
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)*
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)"

  8. #8
    Modérateur
    Avatar de grunk
    Homme Profil pro
    Lead dév - Architecte
    Inscrit en
    Août 2003
    Messages
    6 691
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Lead dév - Architecte
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2003
    Messages : 6 691
    Points : 20 222
    Points
    20 222
    Par défaut
    Nettement plus clair !

    Les lignes intéressantes sont celle ci :

    Caused by: java.lang.ArrayIndexOutOfBoundsException: length=4; index=4
    at com.example.cegelec.cegelecvideo.dummy.DummyContent.<clinit>(DummyContent.java:52)
    at com.example.cegelec.cegelecvideo.ItemVideoListActivity.setupRecyclerView(ItemVideoListActivity.java:70)*
    at com.example.cegelec.cegelecvideo.ItemVideoListActivity.onCreate(ItemVideoListActivity.java:58)*
    ArrayIndexOutOfBoundsException indique que tu essais d'accéder à un élément de tableau qui n'existe pas. Dans ton cas tu essai d'accéder à la case 4 d'un tableau de taille 4 (donc case de 0 à 3). Ce qui provoque l'erreur.
    Pry Framework php5 | N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

Discussions similaires

  1. Problème avec Android Studio
    Par kosher dans le forum Android Studio
    Réponses: 1
    Dernier message: 09/02/2016, 13h59
  2. Problème avec Android Studio
    Par manoi_94 dans le forum Android Studio
    Réponses: 2
    Dernier message: 09/10/2015, 12h55
  3. Problèmes d'affichage de tableau d'objets avec swing
    Par amine1980 dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 04/04/2011, 23h57
  4. [MySQL] problème d'affichage dans tableau avec bdd Mysql
    Par sinifer dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 01/05/2009, 09h50

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