Partage
  • Partager sur Facebook
  • Partager sur Twitter

[Android] Fermeture spontanée sans explications

Sujet résolu
    18 mars 2012 à 13:42:48

    Bonjour à tous,
    J'ai récemment acheté un smartphone, et je suis occupé de créer une application pour gérer mon diabète(insulino-dépendant) au quotidien.
    Pour cela, je me suis mis au Java il y a quelques temps (2-3 semaines), mais je ne puis travailler dessus que les week-ends, et pas beaucoup. Je n'ai donc pas énormément d'expérience en Java.

    J'ai déjà pas mal de connaissances en programmation :
    html, css, php, js, (ajax), python, que je maitrisent bien,
    et aussi d'autres comme la programmation sur ma calculatrice casio 35+ (dont j'ai jamais trouvé le nom du language), l'ActionScript, C(où je suis resté bloqué aux pointeurs), et d'autres encore.
    J'ai toujours voulu commencer le Java, mais le tuto du site du zéro me semblait trop nébuleux. L'occasion de faire une appli pour mon smartphone était un excellent tremplin pour m'y mettre, ce que j'ai fait.
    Tout cela pour dire que Java, je maitrise pas, mais j'ai des notions correctes en programmation.


    En ce qui concerne mon application, lorsque dans l'EditText correspondant à Glycémie, j'entre une valeur, et qu'après je clique sur un des 2 evaluer, l'application se ferme subitement, mais Eclipse ne m'affiche aucune erreur. Pourriez vous m'aider ?
    Merci d'avance.
    Je tiens à préciser qu'avant ça marchait correctement, mais seulement pour des valeurs plus élevées que 120. Cependant, je ne sais plus exactement avant quoi...

    voici mon code java:


    package com.diabete.manager;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Spinner;
    import android.widget.TimePicker;
    import android.widget.Toast;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.View.OnTouchListener;
    
    public class DiabeteManagerActivity extends Activity {
        /** Called when the activity is first created. */
    	private OnTouchListener touchListenerBoutonEvaluer = new OnTouchListener() {
    		public boolean onTouch(View v, MotionEvent event) {
    			/* réagir au toucher pour le bouton 1*/
    			String textToast = "";
    			glycemieValueT = (EditText)findViewById(R.id.glycemieValue);
    			if(glycemieValueT.getText().toString().length() != 0)
    	    	{
    				valeurGly = Integer.parseInt(glycemieValueT.getText().toString());
    		    	if(valeurGly > 120) //TODO: Vérifier pourquoi si j'entre 120 ou moins ca fonctionne pas
    		    	{
    		    		valeurGly = (valeurGly-120)/50;
    		    		textToast += "Il faudrait faire une correction!";
    		    	}
    	    		else
    		    		valeurGly = 0;
    		    	String Snombre = Double.toString(valeurGly);
    		    	monTexte = (EditText)findViewById(R.id.injectionValue);
    		    	int index = Snombre.indexOf(".");
    		    	if (index != -1)
    		    	{
    			    	String SnombreTronque = Snombre.substring(0, index +3);
    			    	valeurGly = Double.parseDouble(SnombreTronque);
    		    	}
    		    	monTexte = (EditText)findViewById(R.id.correctionValue);
    		    	monTexte.setText(String.valueOf(valeurGly));
    	    	}
    			else
    			{
    				monTexte = (EditText)findViewById(R.id.correctionValue);
    		    	monTexte.setText(String.valueOf("0.0"));
    			}
    				
    		    glucideValue = (EditText)findViewById(R.id.glucideValue);
    	    	if(glucideValue.getText().toString().length() != 0)
    	    	{
    	    		valeurGlu = Integer.parseInt(glucideValue.getText().toString());
    	    		valeurGlu = (valeurGlu)/10;
    	    		Spinner spinner = (Spinner) findViewById(R.id.spinner1);
    	    		String Text = spinner.getSelectedItem().toString();
    	    		double ratio = 0.0;
    	    		if (Text == "Hors Repas")
    	    			ratio = 1.0;
    	    		if (Text == "Dejeuner")
    	    			ratio = 1.5;
        			if (Text == "Diner")
        				ratio = 1.2;
    				if (Text == "Souper")
    					ratio = 1.0;
    				valeurGlu = valeurGlu*ratio; // POURQUOI ce point à gauche ?
    				String Snombre = Double.toString(valeurGlu);
    				Snombre = Snombre+"0";
    		    	int index = Snombre.indexOf(".");
    		    	if (index != -1)
    		    	{
    			    	String SnombreTronque = Snombre.substring(0, index +3);
    			    	valeurGlu = Double.parseDouble(SnombreTronque);
    		    	}
    		    	monTexte = (EditText)findViewById(R.id.injectionValue);
    		    	monTexte.setText(String.valueOf(valeurGlu));
    		    	if (textToast.length() != 0)
    		    		textToast += "\n";
    		    	textToast += "Ne pas oublier l'injection!";
    	    	}
    			else{
    				monTexte = (EditText)findViewById(R.id.injectionValue);
    		    	monTexte.setText(String.valueOf("0"));
    			}
    	    	if (textToast.length() != 0){
    	    		Toast toast = Toast.makeText(DiabeteManagerActivity.this, textToast, Toast.LENGTH_LONG);
    	    		toast.setDuration(1);
    	    		toast.show();
    	    	}
    	    	return true;
    		}
    	};
    	private OnTouchListener touchListenerBoutonCorrectionUp = new OnTouchListener() {
    		public boolean onTouch(View v, MotionEvent event) {
    			/* réagir au toucher pour le bouton 1*/
    			if (valeurGly > 0.0)
    			{
    				int i = (int)valeurGly;
    				i = i+1;
    				monTexte = (EditText)findViewById(R.id.correctionValue);
    				monTexte.setText(String.valueOf(i));
    			}
    			return true;
    		}
    	};
    	private OnTouchListener touchListenerBoutonCorrectionDown = new OnTouchListener() {
    		public boolean onTouch(View v, MotionEvent event) {
    			/* réagir au toucher pour le bouton 1*/
    			if (valeurGly > 0.0)
    			{
    				int i = (int)valeurGly;
    				monTexte = (EditText)findViewById(R.id.correctionValue);
    				monTexte.setText(String.valueOf(i));
    			}
    			return true;
    		}
    	};
    	private OnTouchListener touchListenerBoutonInjectionUp = new OnTouchListener() {
    		public boolean onTouch(View v, MotionEvent event) {
    			/* réagir au toucher pour le bouton 1*/
    			if (valeurGlu > 0.0)
    			{
    				int i = (int)valeurGlu;
    				i = i+1;
    				monTexte = (EditText)findViewById(R.id.injectionValue);
    				monTexte.setText(String.valueOf(i));
    			}
    			return true;
    		}
    	};
    	private OnTouchListener touchListenerBoutonInjectionDown = new OnTouchListener() {
    		public boolean onTouch(View v, MotionEvent event) {
    			/* réagir au toucher pour le bouton 1*/
    			if (valeurGlu > 0.0)
    			{
    				int i = (int)valeurGlu;
    				monTexte = (EditText)findViewById(R.id.injectionValue);
    				monTexte.setText(String.valueOf(i));
    			}
    			return true;
    		}
    	};
    	EditText glucideValue = null;
    	TextView monTexte = null;
    	TimePicker monTime = null;
    	EditText glycemieValueT = null;
    	double valeurGly = 0.0;
    	double valeurGlu = 0.0;
    	Button calculGly = null;
    	Button monBouton = null;
    	
    	
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.main);
            
    
        	monTexte = (TextView)findViewById(R.id.heure1);
        	monTexte.setText("Heure: ");
        	monTime = (TimePicker)findViewById(R.id.timePicker1);
        	monTime.setIs24HourView(true);
        	
        	monTexte = (TextView)findViewById(R.id.repas1);
        	monTexte.setText("Repas: ");
        	
        	String[] items = new String[] {"Hors Repas", "Dejeuner", "Diner", "Souper"};
        	Spinner spinner = (Spinner) findViewById(R.id.spinner1);
        	ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
        	            android.R.layout.simple_spinner_item, items);
        	adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        	spinner.setAdapter(adapter);
    
        	
        	monTexte = (TextView)findViewById(R.id.glycemie);
        	monTexte.setText("Glycémie: ");
    
        	monTexte = (TextView)findViewById(R.id.correction);
        	monTexte.setText("Correction: ");
    
        	calculGly = (Button) findViewById(R.id.button1);
            calculGly.setOnTouchListener(touchListenerBoutonEvaluer);
            calculGly.setText("Evaluer");
            monBouton = (Button) findViewById(R.id.button1Up);
            monBouton.setText("+");
            monBouton.setOnTouchListener(touchListenerBoutonCorrectionUp);
            monBouton = (Button) findViewById(R.id.button1Down);
            monBouton.setText("-");
            monBouton.setOnTouchListener(touchListenerBoutonCorrectionDown);
            
        	monTexte = (TextView)findViewById(R.id.glucide);
        	monTexte.setText("Glucides: ");
        	
        	monTexte = (TextView)findViewById(R.id.injection);
        	monTexte.setText("Injection: ");
    
        	calculGly = (Button) findViewById(R.id.button2);
            calculGly.setOnTouchListener(touchListenerBoutonEvaluer);
            calculGly.setText("Evaluer");
            monBouton = (Button) findViewById(R.id.button2Up);
            monBouton.setOnTouchListener(touchListenerBoutonInjectionUp);
            monBouton.setText("+");
            monBouton = (Button) findViewById(R.id.button2Down);
            monBouton.setOnTouchListener(touchListenerBoutonInjectionDown);
            monBouton.setText("-");
        	
        	
        }
    }
    


    Et voici mon code xml

    <?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" >
    
        <LinearLayout
            android:id="@+id/linearLayoutHeure"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
            
            <TextView
    	        android:id="@+id/heure1"
    	        android:layout_width="60sp"
    	        android:layout_height="120sp"
    	        android:text="@string/hello"
    	        android:gravity="center_vertical" />
            
       		<TimePicker
    	        android:id="@+id/timePicker1"
    	        android:layout_width="260sp"
    	        android:layout_height="wrap_content" />
            
            
        </LinearLayout>
        
        <LinearLayout
            android:id="@+id/linearLayoutGlycemie"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
            
            <TextView
    	        android:id="@+id/glycemie"
    	        android:layout_width="80sp"
    	        android:layout_height="wrap_content"
    	        android:text="@string/hello" />
    
    		<EditText
            	android:id="@+id/glycemieValue"
            	android:layout_width="match_parent"
            	android:layout_height="wrap_content"
            	android:inputType="numberSigned"
            	android:imeOptions="actionNext"
            	android:numeric="integer"
            	android:hint="120" >
        	</EditText>
        
        </LinearLayout>
        
        <LinearLayout
            android:id="@+id/linearLayoutGlucide"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
            
            <TextView
    	        android:id="@+id/glucide"
    	        android:layout_width="80sp"
    	        android:layout_height="wrap_content"
    	        android:text="@string/hello" />
    
    		<EditText
            	android:id="@+id/glucideValue"
            	android:layout_width="match_parent"
            	android:layout_height="wrap_content"
            	android:inputType="numberSigned"
            	android:hint="0" >
        	</EditText>
        
        </LinearLayout>
        
    	<LinearLayout
    		android:id="@+id/linearLayoutRepas"
    		android:layout_width="match_parent"
    		android:layout_height="wrap_content"
    		android:orientation="horizontal" >
    		
    		<TextView
    			android:id="@+id/repas1"
    			android:layout_width="80sp"
    			android:layout_height="wrap_content"
    			android:text="@string/hello" />
    		
    		<Spinner
    			android:id="@+id/spinner1"
    			android:layout_width="240sp"
    			android:layout_height="wrap_content" />
    
        </LinearLayout>
        
        <LinearLayout
            android:id="@+id/linearLayoutCorrection"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
            
            <TextView
    	        android:id="@+id/correction"
    	        android:layout_width="80sp"
    	        android:layout_height="wrap_content"
    	        android:text="@string/hello" />
    
    		<EditText
            	android:id="@+id/correctionValue"
            	android:layout_width="80sp"
            	android:layout_height="wrap_content"
            	android:inputType="numberSigned"
            	android:hint="0" >
        	</EditText>
        	
        	<Button
            android:id="@+id/button1Up"
            android:layout_width="40sp"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
        	
        	<Button
            android:id="@+id/button1Down"
            android:layout_width="40sp"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
        	
        	<Button
            android:id="@+id/button1"
            android:layout_width="80sp"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
        
        </LinearLayout>
        
        <LinearLayout
            android:id="@+id/linearLayoutInjection"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
            
            <TextView
    	        android:id="@+id/injection"
    	        android:layout_width="80sp"
    	        android:layout_height="wrap_content"
    	        android:text="@string/hello" />
    
    		<EditText
            	android:id="@+id/injectionValue"
            	android:layout_width="80sp"
            	android:layout_height="wrap_content"
            	android:inputType="numberSigned"
            	android:hint="0" >
        	</EditText>
        	
        	<Button
            android:id="@+id/button2Up"
            android:layout_width="40sp"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
        	
        	<Button
            android:id="@+id/button2Down"
            android:layout_width="40sp"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
        	
        	<Button
            android:id="@+id/button2"
            android:layout_width="80sp"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
        
        </LinearLayout>
    
    </LinearLayout>
    
    • Partager sur Facebook
    • Partager sur Twitter
      18 mars 2012 à 13:55:03

      Tu devrais commencer par logger ton programme. Comme ça, l'erreur est difficile à trouver.

      Regarde de ce coté là, ça devrait de tout façon bien t'aider pour la suite :

      http://mobile.tutsplus.com/tutorials/a [...] _android-sdk/
      • Partager sur Facebook
      • Partager sur Twitter
        19 mars 2012 à 9:29:45

        Bonjour,

        Et également regarder et poster le contenu du LogCat.
        • Partager sur Facebook
        • Partager sur Twitter
          19 mars 2012 à 16:40:25

          Tu as bien sélectionné le mobile /émulateur dans l'onglet "Devices" ? (Ajoute le sinon depuis Windows > Open perspective)
          • Partager sur Facebook
          • Partager sur Twitter
          Recherche des annonceurs incentive pour diffuser sur http://www.envoyer-sms-gratuit.net - Contactez-moi !

          [Android] Fermeture spontanée sans explications

          × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
          × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
          • Editeur
          • Markdown