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 :

erreur avec genymotion


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    275
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

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

    Informations forums :
    Inscription : Février 2012
    Messages : 275
    Par défaut erreur avec genymotion
    Bonjour, j'ai cet erreur avec genymotion. D'où vient cet erreur exactement ? Nom : stop.png
Affichages : 247
Taille : 31,1 Ko
    merci

  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 : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur mobile

    Informations forums :
    Inscription : Février 2010
    Messages : 2 180
    Par défaut
    De ton application qui a crashée.
    Pour que nous puissions t'aider, il nous faut la stacktrace de l'exception, ainsi que le code afférant
    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é
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    275
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

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

    Informations forums :
    Inscription : Février 2012
    Messages : 275
    Par défaut
    Bonjour
    activity_main.xml
    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
     
    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:background="@drawable/login_full2"
        tools:openDrawer="start">
     
        <include
            layout="@layout/app_bar_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
     
        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/activity_main_drawer" />
     
    </android.support.v4.widget.DrawerLayout>
    fragment_main.xml
    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
     
    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent" android:layout_height="match_parent"
        android:paddingTop="120dp"
        android:paddingBottom="16dp"
        android:paddingLeft="50dp"
        android:paddingRight="16dp">
     
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_centerInParent="true"
            android:layout_height="wrap_content">
            <EditText
                android:id="@+id/et_login"
                android:hint="username"
                android:layout_width="150dp"
                android:drawableLeft="@drawable/ic_menu_camera"
                android:layout_height="wrap_content" />
            <EditText
                android:id="@+id/et_password"
                android:hint="password"
                android:inputType="textPassword"
                android:layout_marginTop="10dp"
                android:layout_width="150dp"
                android:layout_height="wrap_content" />
            <Button
                android:id="@+id/btn_valider"
                android:layout_width="150dp"
                android:text="@string/btn_valider"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"/>
        </LinearLayout>
    </FrameLayout>
    MainActivity.java
    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
     
    package com.example.dell.medicalrepresentative;
     
     
    import android.app.FragmentManager;
    import android.content.Intent;
    import android.os.Bundle;
    import android.support.design.widget.FloatingActionButton;
    import android.support.design.widget.Snackbar;
    import android.view.View;
    import android.support.design.widget.NavigationView;
    import android.support.v4.view.GravityCompat;
    import android.support.v4.widget.DrawerLayout;
    import android.support.v7.app.ActionBarDrawerToggle;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;
     
    import com.example.dell.medicalrepresentative.fragments.ImportFragment;
    import com.example.dell.medicalrepresentative.fragments.MainFragment;
     
    public class MainActivity extends AppCompatActivity
            implements NavigationView.OnNavigationItemSelectedListener {
        EditText etLogin,etPassword;
        Button btnValider;
     
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
     
            FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
            fab.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                            .setAction("Action", null).show();
                }
            });
            etLogin=(EditText) findViewById(R.id.et_login);
            etPassword=(EditText) findViewById(R.id.et_password);
            btnValider=(Button) findViewById(R.id.btn_valider);
            btnValider.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View v) {
                    String login = etLogin.getText().toString();
                    String password = etPassword.getText().toString();
                    if(login.equalsIgnoreCase("android")&& password.equalsIgnoreCase("1234"))
                    {
                        Toast.makeText(MainActivity.this, "Success", Toast.LENGTH_SHORT).show();
                    }
                    else{
                        Toast.makeText(MainActivity.this, "Erreur", Toast.LENGTH_SHORT).show();
     
                    }
     
                }
            });
     
     
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                    this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
            drawer.setDrawerListener(toggle);
            toggle.syncState();
     
            NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
            navigationView.setNavigationItemSelectedListener(this);
     
            FragmentManager fm = getFragmentManager();
            fm.beginTransaction().replace(R.id.content_frame, new MainFragment()).commit();
        }
     
        @Override
        public void onBackPressed() {
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            if (drawer.isDrawerOpen(GravityCompat.START)) {
                drawer.closeDrawer(GravityCompat.START);
            } else {
                super.onBackPressed();
            }
        }
     
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
     
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
     
            //noinspection SimplifiableIfStatement
            if (id == R.id.action_settings) {
                return true;
            }
     
            return super.onOptionsItemSelected(item);
        }
     
        @SuppressWarnings("StatementWithEmptyBody")
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {
            FragmentManager fm = getFragmentManager();
            int id = item.getItemId();
     
            if (id == R.id.nav_camera) {
                fm.beginTransaction().replace(R.id.content_frame, new ImportFragment()).commit();
            } else if (id == R.id.nav_gallery) {
     
            } else if (id == R.id.nav_slideshow) {
     
            } else if (id == R.id.nav_manage) {
     
            } else if (id == R.id.nav_share) {
     
            } else if (id == R.id.nav_send) {
     
            }
     
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            drawer.closeDrawer(GravityCompat.START);
            return true;
        }
    }
    J'ai remaqué que cette erreur n'apparait que lorsque j'ai ajouté ces lignes
    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
     
    btnValider.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View v) {
                    String login = etLogin.getText().toString();
                    String password = etPassword.getText().toString();
                    if(login.equalsIgnoreCase("android")&& password.equalsIgnoreCase("1234"))
                    {
                        Toast.makeText(MainActivity.this, "Success", Toast.LENGTH_SHORT).show();
                    }
                    else{
                        Toast.makeText(MainActivity.this, "Erreur", Toast.LENGTH_SHORT).show();
     
                    }
     
                }
            });
    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
     
    04-13 15:55:52.133 15036-15036/com.example.dell.app W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa61ff908)
    04-13 15:55:52.137 15036-15036/com.example.dell.app E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                            java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dell.app/com.example.dell.app.MainActivity}: java.lang.NullPointerException
                                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
                                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
                                                                                                at android.app.ActivityThread.access$600(ActivityThread.java:141)
                                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
                                                                                                at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                at android.os.Looper.loop(Looper.java:137)
                                                                                                at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                                at java.lang.reflect.Method.invoke(Method.java:511)
                                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                                                                at dalvik.system.NativeStart.main(Native Method)
                                                                                             Caused by: java.lang.NullPointerException
                                                                                                at com.example.dell.app.MainActivity.onCreate(MainActivity.java:48)
                                                                                                at android.app.Activity.performCreate(Activity.java:5104)
                                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
                                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
                                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)*
                                                                                                at android.app.ActivityThread.access$600(ActivityThread.java:141)*
                                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)*
                                                                                                at android.os.Handler.dispatchMessage(Handler.java:99)*
                                                                                                at android.os.Looper.loop(Looper.java:137)*
                                                                                                at android.app.ActivityThread.main(ActivityThread.java:5041)*
                                                                                                at java.lang.reflect.Method.invokeNative(Native Method)*
                                                                                                at java.lang.reflect.Method.invoke(Method.java:511)*
                                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)*
                                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)*
                                                                                                at dalvik.system.NativeStart.main(Native Method)*

  4. #4
    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 : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur mobile

    Informations forums :
    Inscription : Février 2010
    Messages : 2 180
    Par défaut
    Normal.
    Ta variable "btnValider" est null.

    Alors, dans l'ordre :

    Caused by: java.lang.NullPointerException at com.example.dell.app.MainActivity.onCreate(MainActivity.java:48)
    Indique tu as une exception "NullPointerException", dans la classe MainActivity du package com.example.dell.app, dans la méthode onCreate, à ligne 48 du fichier MainActivity.java.

    A cette ligne (si l'on excepte le léger décalage de copié/collé) se trouve bien btnValider.setOnClickListener(new View.OnClickListener(). Une NullPointerException est une exception levée lorsque tu tentes d'invoquer une méthode sur un objet nul (ou que tu passes un objet null à une méthode ne le supportant pas).
    Ici donc, la variable btnValider est null, car il n'y a aucun widget correspondant à son ID dans le layout activity_main.xml. Cet ID se trouve dans le Fragment contenu dans l'Activity. Il faut donc que tu rajoutes le code en question dans le Fragment, et non dans l'Activity.

    Je te suggère donc de te renseigner sur les Activity et les Fragment d'Android, histoire que tu comprennes bien ce à quoi chacun sert.
    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

  5. #5
    Membre éclairé
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    275
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

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

    Informations forums :
    Inscription : Février 2012
    Messages : 275
    Par défaut
    Bonsoir
    merci pour votre réponse
    Il faut donc que tu rajoutes le code en question dans le Fragment, et non dans l'Activity.

    Je te suggère donc de te renseigner sur les Activity et les Fragment d'Android, histoire que tu comprennes bien ce à quoi chacun sert.
    Je suis débutante dans la programmation android alors je n'ai pas bien compris qu'est ce que je dois faire . Est ce que je dois insérer cette partie de code dans MainFrament.java
    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
     
     
    btnValider.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View v) {
                    String login = etLogin.getText().toString();
                    String password = etPassword.getText().toString();
                    if(login.equalsIgnoreCase("android")&& password.equalsIgnoreCase("1234"))
                    {
                        Toast.makeText(MainActivity.this, "Success", Toast.LENGTH_SHORT).show();
                    }
                    else{
                        Toast.makeText(MainActivity.this, "Erreur", Toast.LENGTH_SHORT).show();
     
                    }
     
                }
            });

  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 : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur mobile

    Informations forums :
    Inscription : Février 2010
    Messages : 2 180
    Par défaut
    C'est ça.

    Il faut que tu rajoutes ce code (ainsi que l'initialisation du bouton valider et de tes EditText de connexion) dans la méthode "onCreateView" de ton "MainFragment".
    Normalement, ça devrait résoudre cette erreur.
    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

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Erreur Avec Interbase
    Par smokemon dans le forum Bases de données
    Réponses: 1
    Dernier message: 29/10/2004, 07h24
  2. Erreur avec procédure LockWorkStation ...
    Par simonseztech dans le forum API, COM et SDKs
    Réponses: 4
    Dernier message: 16/08/2004, 15h33
  3. [Débutant][Conception] Erreur avec une classe interne
    Par Devil Redneck dans le forum Général Java
    Réponses: 5
    Dernier message: 11/06/2004, 15h45
  4. Erreur avec les ADO
    Par megane dans le forum Bases de données
    Réponses: 7
    Dernier message: 08/03/2004, 21h37
  5. Erreur avec WM_COMMAND (BN_CLICKED)
    Par cyberlewis dans le forum Windows
    Réponses: 2
    Dernier message: 09/02/2004, 00h25

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