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 :

Main qui plante


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur Web et Mobile
    Inscrit en
    Juin 2010
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur Web et Mobile

    Informations forums :
    Inscription : Juin 2010
    Messages : 76
    Par défaut Main qui plante
    Bonjour,

    Je suis en train de péter un plomb devant un code qui marchait très bien il y 1 heure et qui plante dès que je démarre mon application.

    Main.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
    /* Entreprise : Emergence IT
     * Développé par : Maxime Nicole
     * Application : Quiz
     * Version : 1.0
     * Date de création : 02/11/2011
     * Date de modification : 15/11/2011
     */
     
    package fr.emergenceit.quiz;
     
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;
     
    public class Main extends Activity {
     
    	Button btnConnect;
    	Button btnInscrip;
     
        @Override
        public void onCreate(Bundle savedInstanceState) {
     
        	super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
     
        	// On récupère tous les éléments de notre interface grâce aux ID
        	btnConnect = ((Button)this.findViewById(R.id.connection)); // Ligne  31
        	btnInscrip = ((Button)this.findViewById(R.id.inscription));
     
    		// On attribut un écouteur d'évènement à tous les boutons
        	btnInscrip.setOnClickListener(new View.OnClickListener() {
     
    			public void onClick(View v) {
    				goToInscrip();
    			}
     
    		});
     
        	btnConnect.setOnClickListener(new View.OnClickListener() {
     
    			public void onClick(View v) {
    				goToMenuPrinc();
     
    			}
    		});
     
        }//Fin onCreate()
     
    	protected void goToMenuPrinc() {
     
    		//On récupère les deux champs, puis le texte saisi
    		EditText login = (EditText)findViewById(R.id.pseudo);
    		String loginStr = login.getText().toString();
    		EditText pass = (EditText)findViewById(R.id.password);
    		String passStr = pass.getText().toString();
     
    		Intent intent = new Intent(Main.this, Login.class);
     
    		//On rajoute les valeurs à l’Intent
    		//en tant qu’extra a ce dernier.
    		//Les extras sont différenciés par un “id” (string)
    		intent.putExtra("login", loginStr);
    		intent.putExtra("password", passStr);
     
    		//Si un des deux champs est vide, alors on affiche les erreurs
    		if (passStr.equals("") || loginStr.equals("")) {
    			Toast.makeText(getBaseContext(),
    			"Le Pseudo et le Mot de passe sont obligatoires",
    			Toast.LENGTH_SHORT).show();
    			return;
    		}
     
    		//Si on respecte les conditions plus haut
    		//On accède à l'écran du menu principal
    		this.startActivity(intent);
     
    	}
     
    	protected void goToInscrip() {
    		Intent intent = new Intent(this, Inscription.class);				
    		//On démarre l'activité
    		this.startActivity(intent);
     
    	}
     
    	@Override
    	protected void onDestroy() {
    		//On arrête le service : "ServicePacks". (qui a été démarré dans MenuPrincipal.java
    		//Intent bindIntent = new Intent(this, ServicePacks.class);
    		//stopService(bindIntent);
    		super.onDestroy();
    	}
    }
    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
    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
     
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" 
        android:background="@drawable/bg">
     
    	<LinearLayout
    	    android:id="@+id/linearLayout1"
    	    android:layout_width="wrap_content"
    	    android:layout_height="wrap_content" 
    	    android:layout_gravity="right" 
    	    android:layout_marginTop="30px">
     
    		<TextView
    		    android:layout_width="wrap_content"
    		    android:layout_height="wrap_content"
    		    android:layout_weight="0.00"
    		    android:paddingTop="10dp"
    		    android:text="Pseudo : "
    		    android:textColor="#FFFFFF" 
    		    android:textSize="20dp" 
    		    android:layout_marginRight="20px"/>
     
    		<EditText
    		    android:id="@+id/pseudo"
    		    android:layout_width="200dp"
    		    android:layout_height="wrap_content"
    		    android:layout_marginRight="20px"
    		    android:layout_weight="0.00" 
    		    android:layout_gravity="right" android:saveEnabled="true" android:text="Xenonmax">
     
    		    <requestFocus />
    		</EditText>
     
    	</LinearLayout>
     
    	<LinearLayout
    	    android:id="@+id/linearLayout2"
    	    android:layout_width="wrap_content"
    	    android:layout_height="wrap_content" 
    	    android:layout_gravity="right">
     
    		<TextView
    		    android:layout_width="wrap_content"
    		    android:layout_height="wrap_content"
    		    android:paddingTop="10dp"
    		    android:text="Mot de passe : "
    		    android:textColor="#FFFFFF" 
    		    android:layout_marginRight="20px" 
    		    android:textSize="20dp"/>
     
    		<EditText
    		    android:id="@+id/password"
    		    android:layout_width="200dp"
    		    android:layout_height="wrap_content"
    		    android:layout_weight="1"
    		    android:password="true" 
    		    android:layout_marginRight="20px" 
    		    android:saveEnabled="true" 
    		    android:text="******"/>
     
    	</LinearLayout>
     
    	<CheckBox
    	    android:id="@+id/checkBox1"
    	    android:layout_width="wrap_content"
    	    android:layout_height="wrap_content"
    	    android:text="@string/souvenir" 
    	    android:layout_gravity="right" 
    	    android:layout_marginRight="40px" 
    	    android:textColor="#FFFFFF"/>
     
    	<LinearLayout
    	    android:id="@+id/linearLayout3"
    	    android:layout_width="wrap_content"
    	    android:layout_height="wrap_content"
     		    android:layout_gravity="right">
     
     
    		<Button
    		    android:id="@+id/inscription"
    		    android:layout_width="wrap_content"
    		    android:layout_height="wrap_content"
    		    android:layout_marginRight="100px"
    		    android:layout_marginTop="10dp"
    		    android:text="Créer un compte" />
     
     
    		<Button
    		    android:id="@+id/connection"
    		    android:layout_width="wrap_content"
    		    android:layout_height="wrap_content"
    		    android:layout_gravity="right"
    		    android:layout_marginRight="30px"
    		    android:layout_marginTop="10dp"
    		    android:text="Se connecter" />
     
    	</LinearLayout>
     
    </LinearLayout>
    Log Cat :
    Uncaught handler: thread main exiting due to uncaught exception
    java.lang.RuntimeException: Unable to start activity ComponentInfo{fr.emergenceit.quiz/fr.emergenceit.quiz.Main}: java.lang.ClassCastException: android.widget.EditText
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
    at android.app.ActivityThread.access$2200(ActivityThread.java:119)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4363)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.ClassCastException: android.widget.EditText
    at fr.emergenceit.quiz.Main.onCreate(Main.java:31)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
    Pourriez vous m'aider ?

    Merci d'avance pour vos réponses.

  2. #2
    Membre expérimenté Avatar de chpil
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    143
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations forums :
    Inscription : Octobre 2011
    Messages : 143
    Par défaut
    L'exception dit que le composant que tu essayes de récupérer via le findViewById (dont l'id est connection) serait un EditText, alors que tu veux récupérer un Button, d'où l'exception.
    Pour autant, dans ton main.xml, il s'agit bien d'un EditText
    Je ne vois qu'une explication: le projet est désynchroniser en ce qui concerne le code généré par le plug-in ADT. Il devrait te suffire de cleaner le projet et de le recompiler (menu Project/Clean et Project/Build Project)

  3. #3
    Membre confirmé
    Homme Profil pro
    Développeur Web et Mobile
    Inscrit en
    Juin 2010
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur Web et Mobile

    Informations forums :
    Inscription : Juin 2010
    Messages : 76
    Par défaut
    Merci bien, je connaissais pas cette astuce.

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

Discussions similaires

  1. PB d'update qui plante aléatoirement sans renvoyer d'erreur
    Par plc402 dans le forum MS SQL Server
    Réponses: 5
    Dernier message: 01/08/2005, 09h10
  2. [Novice] Problème avec Eclipse 3.0.x qui plante
    Par esolarc dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 27/05/2005, 13h22
  3. Programme qui plante
    Par harris_macken dans le forum C++
    Réponses: 1
    Dernier message: 22/05/2005, 23h50
  4. Pc qui plante
    Par tooms2028 dans le forum Ordinateurs
    Réponses: 9
    Dernier message: 19/03/2005, 17h32
  5. [JTextArea] redessin qui plante
    Par phil_ma dans le forum Composants
    Réponses: 3
    Dernier message: 04/01/2005, 05h19

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