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 :

Problème date (getTime() )


Sujet :

Android

  1. #1
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 33
    Points : 15
    Points
    15
    Par défaut Problème date (getTime() )
    j ai ce code
    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
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
     
    package com.example.mobilebanque;
     
     
     
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
     
    import android.app.Activity;
    import android.app.DatePickerDialog;
    import android.app.Dialog;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;
    import android.app.Activity;
    import android.app.DatePickerDialog;
    import android.app.Dialog;
    import android.text.TextWatcher;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.text.Editable;
    import java.util.Calendar;
    import java.lang.Object;
     
     
     
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
     
     
     
     
     
     
     
     
     
     
     
     
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
     
     
     
     
     
     
    //import android.app.Activity;
    //import android.os.Bundle;
    //import android.view.KeyEvent;
    //import android.view.MotionEvent;
    import android.view.View;
    import android.view.View.OnClickListener;
    //import android.view.View.OnKeyListener;
    import android.widget.Button;
    import android.widget.CheckBox;
    import android.widget.DatePicker;
    import android.widget.EditText;
    import android.widget.ImageButton;
    import android.widget.RadioGroup;
    import android.widget.TextView;
    import android.widget.Toast;
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.content.Intent;
     
    public class RechercherTransactions extends Activity {
    	Calendar c;
    	Calendar cal;
    	//Database datasource=new Database(this);
    	TextView essai;
    	String dat;
    	java.util.Date d1;
    	java.util.Date d2;
    	java.util.Date d3;
    	long dd1;
    	long dd2;
    	long dd3;
    	private int day;
    	 private int month;
    	 private int year;
    	 private final int fromDATE_DIALOG = 1;
    	 private final int toDATE_DIALOG = 2;
    	String agec_de_historique; 
    	public final static String AGECONS="bb";
    	  public final  static String AGEC="a";
    	   TextView  datt;
    	  private EditText editFromDate,editToDate,cpte1;
    	private int fromDay=17;
    	private int	fromMonth=05;
    	private int	 fromYear=2015;
    	private int toDay=17, toMonth=05, toYear=2015;
    	private final int FROM_DATE_DIALOG = 1;
    	private final int TO_DATE_DIALOG = 2;
         String chaine1;
         String chaine2;
         String chaine3;
     
         Database clientbBdd = new Database(this);
     
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.recherchertransactions);
     
    		editFromDate = (EditText) this.findViewById(R.id.editFromDate);
    		editToDate = (EditText) this.findViewById(R.id.editToDate);
     
    		cpte1 = (EditText) this.findViewById(R.id.cpte1);
     
    		Intent i = getIntent();
     
    	     agec_de_historique= i.getStringExtra(Connexion.AGEC);
    	     datt = (TextView)findViewById(R.id.dat);
    	     essai = (TextView)findViewById(R.id.essai);
    		    essai.setText(agec_de_historique);
     
     
     
            c = Calendar.getInstance();
            fromYear = toYear = c.get(Calendar.YEAR);
            fromMonth  = toMonth = c.get(Calendar.MONTH);
            toDay = c.get(Calendar.DAY_OF_MONTH);
     
     
    	}
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		return Utils.inflateMenu(this,menu);
    	}
     
    	@Override 
    	public boolean onOptionsItemSelected(MenuItem item) {
    		return  Utils.handleMenuOption(this,item);
    	}
     
     
     
    	  private DatePickerDialog.OnDateSetListener dateSetListener = new DatePickerDialog.OnDateSetListener() {
    	   public void onDateSet(DatePicker view, int selectedYear,
    	     int selectedMonth, int selectedDay) {
    		   editFromDate.setText( selectedYear+ " / " + (selectedMonth + 1) + " / "
    	      + selectedDay);
     
    	   }
    	  };
    	  private DatePickerDialog.OnDateSetListener dateSetListenerr = new DatePickerDialog.OnDateSetListener() {
    		   public void onDateSet(DatePicker view, int selectedYear,
    		     int selectedMonth, int selectedDay) {
    			   editToDate.setText(selectedYear+ " / " + (selectedMonth + 1) + " / "
    		      +selectedDay  );
     
    		   }
    		  };
     
    	  @Override 
    		public void onStart() {
    			super.onStart();
     
    		}
     
    	  public void showDateDialog(View v) {
    		  showDialog(fromDATE_DIALOG);
     
    	}
    	  public void showDateDialogg(View v) {
    		  showDialog(toDATE_DIALOG);
    	}
     
    	  @Override
    		protected Dialog onCreateDialog(int id) {
    		    switch (id) {
    		    case fromDATE_DIALOG:
    		        return new DatePickerDialog(this,
    		        		dateSetListener, fromYear, fromMonth, fromDay);
    		    case toDATE_DIALOG:
    		        return new DatePickerDialog(this,
    		        		dateSetListenerr, toYear, toMonth, toDay);
    		    }
    		    return null;
    		}
     
     
    	public void searchTransactions(View v) {
    		 Database dbUser = new Database(RechercherTransactions.this);
    			dbUser.open();
     
    		 chaine1 = cpte1.getText().toString();
    		 chaine2 = editFromDate.getText().toString();
    		 chaine3 = editToDate.getText().toString();
     
     
     
     
    		 if((chaine1.equals(""))|| (chaine2.equals("")) || (chaine3.equals("")))
    			    	{
    			 Toast.makeText(RechercherTransactions.this,"veuillez remplir tous les champs", Toast.LENGTH_LONG).show();;
     
    			    	 }
     
     
    		 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    		 String kk=format.format(c.getTime());
    		  if(chaine1.length() > 0 && chaine2.length() > 0 && chaine3.length() > 0)
    				{
     
    				 try {
    					 d1=format.parse(chaine2);
    					  d2=format.parse(chaine3);
    					 // d3 = format.parse(dat);
    				} catch (ParseException e1) {
    					// TODO Auto-generated catch block
    					e1.printStackTrace();
    				}
     
     
     
     
     
     
     
    				   dd1=d1.getTime();//fromdate ON ME SIGNALE CETTE LIGNE 
    				  dd2=d2.getTime();//todate
     
    					if(dd2>dd1)
    					{
     
    						dbUser.open();
     
     
     
     
     
     
     
    						if(dbUser.Auth_compte(chaine1) ) 
    					      {	
     
    					    	  //dat_fin = datasource.recuperer_date_fin_off(id_offre);
    					    	 // dbUser.close();
    							 dat = dbUser.recuperer_date_trans(chaine1);
    							  datt.setText(dat);
    							  dbUser.close();
    							  if (dat!=null)
    							  {
    					    	   try {
    								 d3 = format.parse(dat);
    								 //f1 = sdf.parse(dat_fin);
    							} catch (ParseException e) {
    								// TODO Auto-generated catch block
    								e.printStackTrace();
    							}
    					    	   dd3= d3.getTime();//date bdd
    							  }dbUser.open();
    							  if( dbUser.transfert( agec_de_historique,chaine1)==true)
     
    								{
    							if( dd2>=dd3 )//la 2eme depasse la date de la trans bdd
    							{
    								if( dd1<=dd3)
    								{	
     
    							//if (dbUser.ConsultationSolde(agec_de_historique,chaine1)==null ) 
     
      	    	   Intent secondeActivitee=new Intent(RechercherTransactions.this, ListeTransactions.class);
     
      	    	 secondeActivitee.putExtra("fromdate", chaine2);
      	    	secondeActivitee.putExtra("todate", chaine3);
      	    	secondeActivitee.putExtra("numcpte1", chaine1);
     
    			     startActivity(secondeActivitee);
    			    dbUser.close();
    							}
     
    						else //Toast.makeText(RechercherTransactions.this,"pas de trans la trans est avant", Toast.LENGTH_LONG).show();
     
    							{Intent secondeActivitee=new Intent(RechercherTransactions.this, ListeTransaction.class);
    							 startActivity(secondeActivitee);
    							 }
     
     
    				}
    						else
    									{Intent secondeActivitee=new Intent(RechercherTransactions.this, ListeTransaction.class);
    									 startActivity(secondeActivitee);
    									 }
    							//Toast.makeText(RechercherTransactions.this,"pa de transs la trans est apres", Toast.LENGTH_LONG).show();
     
    							}else Toast.makeText(RechercherTransactions.this,"ce num nest pas le votre", Toast.LENGTH_LONG).show();
     
    						}
    					else
    						Toast.makeText(RechercherTransactions.this,"Ce numero de compte n'existe pas", Toast.LENGTH_LONG).show();
     
     
    					}else Toast.makeText(RechercherTransactions.this,"la premiére date doit être  inferieure à la deuxieme", Toast.LENGTH_LONG).show();	
     
      			} else 
    						Toast.makeText(RechercherTransactions.this,"Veuillez remplir tous les champs", Toast.LENGTH_LONG).show();
     
     
     
     
     
     
    }
    ;
     
     
     
     
     
     
     
     
     
     
    	 public void listAccountTransactions(View v) {
    	    	Intent intent = new Intent(this,DetailsTransactions.class);
    	    	intent.putExtra("accountid", chaine1);
    	    	startActivity(intent);
    		}
     
    }
    voila ce que dit le logcat
    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
     
    05-17 19:35:52.943: E/AndroidRuntime(773): FATAL EXCEPTION: main
    05-17 19:35:52.943: E/AndroidRuntime(773): java.lang.IllegalStateException: Could not execute method of the activity
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at android.view.View$1.onClick(View.java:2072)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at android.view.View.performClick(View.java:2408)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at android.view.View$PerformClick.run(View.java:8816)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at android.os.Handler.handleCallback(Handler.java:587)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at android.os.Handler.dispatchMessage(Handler.java:92)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at android.os.Looper.loop(Looper.java:123)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at android.app.ActivityThread.main(ActivityThread.java:4627)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at java.lang.reflect.Method.invokeNative(Native Method)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at java.lang.reflect.Method.invoke(Method.java:521)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at dalvik.system.NativeStart.main(Native Method)
    05-17 19:35:52.943: E/AndroidRuntime(773): Caused by: java.lang.reflect.InvocationTargetException 
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at com.example.mobilebanque.RechercherTransactions.searchTransactions(RechercherTransactions.java:306)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at java.lang.reflect.Method.invokeNative(Native Method)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at java.lang.reflect.Method.invoke(Method.java:521)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	at android.view.View$1.onClick(View.java:2067)
    05-17 19:35:52.943: E/AndroidRuntime(773): 	... 11 more
    05-17 19:35:52.943: E/AndroidRuntime(773): Caused by: java.lang.NullPointerException
    05-17 19:35:52.943: E/AndroidRuntime(773): 	... 15 more
    la ligne 306 c'est dd1=d1.getTime();

    ou est le pb SVP,?

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

    Informations professionnelles :
    Activité : Développeur mobile

    Informations forums :
    Inscription : Février 2010
    Messages : 2 180
    Points : 5 072
    Points
    5 072
    Par défaut
    Premier problème : les noms de tes variables. d1, dd1... en quoi est-ce parlant ? Qu'est-ce que cela représente ? Prend l'habitude de donner des noms parlant à tes variables et à tes méthodes.
    Deuxième problème : les visiblités. En Java, on a pour convention de mettre en "private" par défaut, et d'exposer s'il le faut ensuite (soit via un public dans le cas des POJO, soit via des accesseurs).
    Troisième problème : l'indentation du code. Pense à bien l'indenter (les IDE et éditeurs de textes évolués le font automatiquement), ça facilite grandement la lisibilité pour tout le monde (y compris toi).

    Tu as au moins un ; qui se trimballe tout seul.

    Tes exceptions sont mal gérées, et c'est la cause de ton problème. Pas de printStackTrace sur Android, il n'y a aucune garantie sur la sortie stdout. Utilise plutôt Log.e(TAG, "message", e);.
    Ton problème est une NullPointerException (NPE) qui consiste en l'appel d'une méthode sur un objet null, ou la transmission d'un paramètre null à une méthode ne le prenant pas en charge.
    Tu devrais avoir une ParseException dans ton LogCat disant, grosso-modo "je n'arrive pas à parser chaîne2", d'où d1 à null, d'où la NPE.

    Je te suggère donc de mettre tout le code dépendant du parsing dans le try, ou au moins, de contrôler les valeurs après le parsing.
    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 à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 33
    Points : 15
    Points
    15
    Par défaut
    merci pr vos remarques.
    j ai deplacé le code concernant le conversion en "time" dans le try mais j 'ai tjr un pb : qd je fais la comparaison des valeurs converties il m'execute tjr le else (la 1ere date doit etre inferieure à la 2eme)mm si la condition est juste comme je l ai précisé dans le code suivant
    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
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
     
    package com.example.mobilebanque;
     
     
     
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
     
    import android.app.Activity;
    import android.app.DatePickerDialog;
    import android.app.Dialog;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.DatePicker;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;
    //import android.app.Activity;
    //import android.os.Bundle;
    //import android.view.KeyEvent;
    //import android.view.MotionEvent;
    //import android.view.View.OnKeyListener;
     
    public class RechercherTransactions extends Activity {
    	Calendar c;
    	Calendar cal;
    	//Database datasource=new Database(this);
    	TextView essai;
    	String dat;
    	java.util.Date d1;
    	java.util.Date d2;
    	java.util.Date d3;
    	long dd1;
    	long dd2;
    	long dd3;
    	private int day;
    	 private int month;
    	 private int year;
    	 private final int fromDATE_DIALOG = 1;
    	 private final int toDATE_DIALOG = 2;
    	String agec_de_historique; 
    	public final static String AGECONS="bb";
    	  public final  static String AGEC="a";
    	   TextView  datt;
    	  private EditText editFromDate,editToDate,cpte1;
    	private int fromDay=17;
    	private int	fromMonth=05;
    	private int	 fromYear=2015;
    	private int toDay=18, toMonth=05, toYear=2015;
     
         String chaine1;
         String chaine2;
         String chaine3;
     
         Database clientbBdd = new Database(this);
     
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.recherchertransactions);
     
    		editFromDate = (EditText) this.findViewById(R.id.editFromDate);
    		editToDate = (EditText) this.findViewById(R.id.editToDate);
     
    		cpte1 = (EditText) this.findViewById(R.id.cpte1);
     
    		Intent i = getIntent();
     
    	     agec_de_historique= i.getStringExtra(Connexion.AGEC);
    	     datt = (TextView)findViewById(R.id.dat);
    	     essai = (TextView)findViewById(R.id.essai);
    		    essai.setText(agec_de_historique);
     
     
     
     
            c = Calendar.getInstance();
            fromYear = toYear = c.get(Calendar.YEAR);
            fromMonth  = toMonth = c.get(Calendar.MONTH);
            toDay = c.get(Calendar.DAY_OF_MONTH);
     
    	}
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		return Utils.inflateMenu(this,menu);
    	}
     
    	@Override 
    	public boolean onOptionsItemSelected(MenuItem item) {
    		return  Utils.handleMenuOption(this,item);
    	}
     
     
     
    	  private DatePickerDialog.OnDateSetListener dateSetListener = new DatePickerDialog.OnDateSetListener() {
    	   public void onDateSet(DatePicker view, int selectedYear,
    	     int selectedMonth, int selectedDay) {
    		   editFromDate.setText( selectedYear+ " / " + (selectedMonth + 1) + " / "
    	      + selectedDay);
     
    	   }
    	  };
    	  private DatePickerDialog.OnDateSetListener dateSetListenerr = new DatePickerDialog.OnDateSetListener() {
    		   public void onDateSet(DatePicker view, int selectedYear,
    		     int selectedMonth, int selectedDay) {
    			   editToDate.setText(selectedYear+ " / " + (selectedMonth + 1) + " / "
    		      +selectedDay  );
     
    		   }
    		  };
     
    	  @Override 
    		public void onStart() {
    			super.onStart();
     
    		}
     
    	  public void showDateDialog(View v) {
    		  showDialog(fromDATE_DIALOG);
     
    	}
    	  public void showDateDialogg(View v) {
    		  showDialog(toDATE_DIALOG);
    	}
     
    	  @Override
    		protected Dialog onCreateDialog(int id) {
    		    switch (id) {
    		    case fromDATE_DIALOG:
    		        return new DatePickerDialog(this,
    		        		dateSetListener, fromYear, fromMonth, fromDay);
    		    case toDATE_DIALOG:
    		        return new DatePickerDialog(this,
    		        		dateSetListenerr, toYear, toMonth, toDay);
    		    }
    		    return null;
    		}
     
     
    	public void searchTransactions(View v) {
    		 Database dbUser = new Database(RechercherTransactions.this);
    			dbUser.open();
     
    		 chaine1 = cpte1.getText().toString();//numero de compte
    		 chaine2 = editFromDate.getText().toString();//date debut
    		 chaine3 = editToDate.getText().toString();//date fin
     
     
     
    		 if((chaine1.equals(""))|| (chaine2.equals("")) || (chaine3.equals("")))
    			    	{
    			 Toast.makeText(RechercherTransactions.this,"veuillez remplir tous les champs", Toast.LENGTH_LONG).show();;
     
     
    			    	 }
     
     
    		 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    				  if(chaine1.length() > 0 && chaine2.length() > 0 && chaine3.length() > 0)
    				{
     
    				 try {
    					 d1=format.parse(chaine2); );//conversion en date de date debut
     
    					  d2=format.parse(chaine3); );//conversion en date de date fin
     
     
    					  dd1=d1.getTime(););//conversion en scdes de date debut
     
     
    					  dd2=d2.getTime(););//conversion en scdes de date fin
     
    				} catch (ParseException e1) {
    					// TODO Auto-generated catch block
    					e1.printStackTrace();
    				}
     
     
     
     
     
     
     
     
     
     
    					if(dd2>dd1)//LE PB CEST QUIL EXECUTE TOUJOURS LE ELSE DE CETTE CONDITION MEME SI dd2(DATE FIN) EST SUPPERIER à dd1(DATE DEBUT)
     
    					{
     
    						dbUser.open();
     
     
     
     
     
     
     
    						if(dbUser.Auth_compte(chaine1) ) 
    					      {	
     
     
    							 dat = dbUser.recuperer_date_trans(chaine1);//dat :date recupérée de la bdd avc laquelle je fais la comparaison
    							  datt.setText(dat);
    							  dbUser.close();
    							  if (dat!=null)
    							  {
     
    							  dbUser.open();
    							  if( dbUser.transfert( agec_de_historique,chaine1)==true)
     
    								{
     
     
      	    	   Intent secondeActivitee=new Intent(RechercherTransactions.this, ListeTransactions.class);
     
      	    	 secondeActivitee.putExtra("fromdate", chaine2);
      	    	secondeActivitee.putExtra("todate", chaine3);
      	    	secondeActivitee.putExtra("numcpte1", chaine1);
     
    			     startActivity(secondeActivitee);
    			    dbUser.close();
    							}
     
     
    							else Toast.makeText(RechercherTransactions.this,"ce num nest pas le votre", Toast.LENGTH_LONG).show();
     
    						}
    					else
    						Toast.makeText(RechercherTransactions.this,"Ce numero de compte n'existe pas", Toast.LENGTH_LONG).show();
     
     
    					}else Toast.makeText(RechercherTransactions.this,"la premiére date doit être  inferieure à la deuxieme", Toast.LENGTH_LONG).show();	
     
      			} else 
    						Toast.makeText(RechercherTransactions.this,"Veuillez remplir tous les champs", Toast.LENGTH_LONG).show();
     
     
     
     
     
     
    }
    ;
     
     
     
     
     
     
     
     
    	public void clearFields(View v) {
     
               editFromDate.setText("");
               editToDate.setText("");
               cpte1.setText("");
     
    	} 
     
     
    	 public void listAccountTransactions(View v) {
    	    	Intent intent = new Intent(this,DetailsTransactions.class);
    	    	intent.putExtra("accountid", chaine1);
    	    	startActivity(intent);
    		}
     
    }
    JE NE SAIS PAS OU EST L'ERREUR
    j ai essaye de comparer les dates (d1 et d2) sans les transformer en time avc compareto() et avec after (d1.after(d2)) ça ne marche pas j 'ai un force close
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    05-18 21:48:26.370: E/AndroidRuntime(12221): Caused by: java.lang.reflect.InvocationTargetException
    05-18 21:48:26.370: E/AndroidRuntime(12221): Caused by: java.lang.NullPointerException

  4. #4
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Ton erreur est ici :
    at com.example.mobilebanque.RechercherTransactions.searchTransactions(RechercherTransactions.java:306)

    Après dis moi ce que tu as à cette ligne ?

    Sinon pour comparer des dates tu as la méthode compareTo http://developer.android.com/referen...ava.util.Date)
    qui est fait pour !

    Il faudrait voir ce que tu as dans chaine2 et chaine3 si j'ai bien vu ?
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  5. #5
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 33
    Points : 15
    Points
    15
    Par défaut
    au fait j ai fais une erreur au niveau du format (j ai mis des /) alr que le format que j 'ai defini lors de la conversion est avec des (-) , c'est pr ça que le parse ne marchait pas.


    je ne sais pas pourquoi l'affichage de mes dates dans les edittext est de cette forme (2015-5-6) le jour et le mois sur une position , ça me cause des pb comment faire pour que le jour et le mois soient affichés sur 2 positions (2015-05-06) (malgré que j ai defini le format : yyyy-MM-dd)

    svp auriez vous une idee??
    merci

  6. #6
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    tu récupères les données via ton split, ensuite tu utilises la class DecimalFormat pour rajouter le 0 si nécessaire

    Détail des nouvelles entrées dont les principaux thèmes des tutoriels ajoutés

    du style

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DecimalFormat dec = new DecimalFormat("00");
    pour avoir les données numériques sur une longueur de deux obligatoirement
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  7. #7
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 33
    Points : 15
    Points
    15
    Par défaut
    comment appliquer ce format à mes valeurs de selectedMonth, selectedDay ( qui sont des int) que je vx afficher sur 2 postions dans mes edittext ?

  8. #8
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Ben tu convertie tes entiers en string puis tu utilises DeimalFormat pour les avoir sur deux caractères


    Tu peux limiter le nombre de caractères dans tes EditText mais penses plutôt à convertir les données avant de les utilser.

    Si ela te pose réellement problème tu peux utiliser le DatePickerDialog qui est prévu pour cela.
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  9. #9
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 33
    Points : 15
    Points
    15
    Par défaut
    j'ai changé de code pour la recupération de la date du datepicker et j ai trouvé un moyen pour afficher le jour et le mois sur deux positions
    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
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
     
    package com.example.mobilebanque;
     
     
     
    import java.text.DecimalFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
     
    import android.app.Activity;
    import android.app.DatePickerDialog;
    import android.app.Dialog;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.DatePicker;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;
     
    public class RechercherTransactions extends Activity {
    	Calendar c;
    	//Database datasource=new Database(this);
    	TextView essai;
    	String dat;
    	java.util.Date d1;
    	java.util.Date d2;
    	java.util.Date d3;
    	long dd1;
    	long dd2;
    	long dd3;
    	String fromDayy;
    	String agec_de_historique; 
    	public final static String AGECONS="bb";
    	  public final  static String AGEC="a";
    	   TextView  datt;
    	  private EditText editFromDate,editToDate,cpte1;
    	private int fromDay, fromMonth, fromYear;
    	private int toDay, toMonth, toYear;
    	private final int FROM_DATE_DIALOG = 1;
    	private final int TO_DATE_DIALOG = 2;
         String chaine1;
         String chaine2;
         String chaine3;
     
         Database clientbBdd = new Database(this);
     
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.recherchertransactions);
     
    		editFromDate = (EditText) this.findViewById(R.id.editFromDate);
    		editToDate = (EditText) this.findViewById(R.id.editToDate);
     
    		cpte1 = (EditText) this.findViewById(R.id.cpte1);
     
    		Intent i = getIntent();
     
    	     agec_de_historique= i.getStringExtra(Connexion.AGEC);
    	     datt = (TextView)findViewById(R.id.dat);
    	     essai = (TextView)findViewById(R.id.essai);
    		    essai.setText(agec_de_historique);
     
     
     
     
     
    		 // get the current date
            c = Calendar.getInstance();
            fromYear = toYear = c.get(Calendar.YEAR);
            fromMonth  = toMonth = c.get(Calendar.MONTH);
            toDay = c.get(Calendar.DAY_OF_MONTH);
     
     
     
     
     
            fromDay  = 1;  // from is set to 1st of the current month 
     
     
           updateToDateDisplay();
           updateFromDateDisplay();
    	}
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		return Utils.inflateMenu(this,menu);
    	}
     
    	@Override 
    	public boolean onOptionsItemSelected(MenuItem item) {
    		return  Utils.handleMenuOption(this,item);
    	}
     
     
    	private DatePickerDialog.OnDateSetListener fromDateSetListener =
                new DatePickerDialog.OnDateSetListener() {
                    public void onDateSet(DatePicker view, int pYear,int pMonth, int pDay) {
                        fromYear = pYear;
                        fromMonth = pMonth;
                        fromDay = pDay;
                        updateFromDateDisplay();
                    }
                };
     
       	private DatePickerDialog.OnDateSetListener toDateSetListener =
                        new DatePickerDialog.OnDateSetListener() {
                            public void onDateSet(DatePicker view, int pYear,int pMonth, int pDay) {
                                toYear = pYear;
                                toMonth = pMonth;
                                toDay = pDay;
                                updateToDateDisplay();
                            }
                        };
     
    	public void showFromDateDialog(View v) {
    		  showDialog(FROM_DATE_DIALOG);
    	}
     
    	public void showToDateDialog(View v) {
    		  showDialog(TO_DATE_DIALOG);
    	}
     
    	@Override
    	protected Dialog onCreateDialog(int id) {
    	    switch (id) {
    	    case FROM_DATE_DIALOG:
    	        return new DatePickerDialog(this,
    	                    fromDateSetListener, fromYear, fromMonth, fromDay);
    	    case TO_DATE_DIALOG:
    	        return new DatePickerDialog(this,
    	                    toDateSetListener, toYear, toMonth, toDay);
    	    }
    	    return null;
    	}
     
    	private void updateToDateDisplay() {// affichage de la date dans l'editetext de date fin
     
                // Month is 0 based so add 1
    	if (toMonth==10 && toDay<10)// meme en rajoutant cette condition le mois d'octobre est affiché comme : 010
    		editToDate.setText( String.format("%d-%d-0%d",toYear,toMonth + 1,toDay));
     
    	else if (toMonth==10 && toDay>=10)
    		editToDate.setText( String.format("%d-%d-%d",toYear,toMonth + 1,toDay));
     
    	else if (toDay<10 && toMonth<10)
    	        editToDate.setText( String.format("%d-0%d-0%d",toYear,toMonth + 1,toDay));
     
    		else if (toMonth<10 && toDay>=10)
    		 editToDate.setText( String.format("%d-0%d-%d",toYear,toMonth + 1,toDay));
     
    		else if (toDay<10 && toMonth>=10)
    			 editToDate.setText( String.format("%d-%d-0%d",toYear,toMonth + 1,toDay));
    		else 
    			//if (toDay>=10 && toMonth>=10)
    			editToDate.setText( String.format("%d-%d-%d",toYear,toMonth + 1,toDay));
     
    	}
    	private void updateFromDateDisplay() {// affichage de la date dans l'editetext de date debut
            // Month is 0 based so add 1
    		if (fromMonth==10 && fromDay<10)
    			  editFromDate.setText( String.format("%d-%d-0%d",fromYear,fromMonth + 1,fromDay));
     
    		else if (fromMonth==10 && fromDay>=10)
    			  editFromDate.setText( String.format("%d-%d-0%d",fromYear,fromMonth + 1,fromDay));
     
    		else if (fromDay<10 && fromMonth<10)
            editFromDate.setText( String.format("%d-0%d-0%d",fromYear,fromMonth + 1,fromDay));
     
    		else if  (fromMonth<10 && fromDay>=10)
    		 editFromDate.setText( String.format("%d-0%d-%d",fromYear,fromMonth + 1,fromDay));
    		 else if (fromDay<10 || fromMonth>=10)
     
    			 editFromDate.setText( String.format("%d-%d-0%d",fromYear,fromMonth + 1,fromDay));
     
    		 else editFromDate.setText( String.format("%d-%d-%d",fromYear,fromMonth + 1,fromDay));
    }
    tout va bien pr tous les mois sauf octobre il rajoute un 0 , dnc c'est affiché comme ceci :010
    alr SVP dites moi ou peut etre le pb au niveau de mes conditions
    MERCI

  10. #10
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    J'aurai bien deux questions.

    1. Pourquoi ne pas simplement utiliser un SimpleDateFormat....

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    SimpleDateFormat df = new SimpleDateFormat("YY-MM-DD");
    textView.setText(df.format(date));

    2. Pourquoi stocker autant de variables dans l'activité ? la plupart d'entre elles ne sont utilisées que pendant de courts laps de temps (et devraient donc être locales aux fonctions).


    P.S.
    Et pourquoi ne pas utiliser %02d (qui veut dire un entier décimal, avec 2 chiffres, et un leading 0 si besoin).
    Dans tous les cas: format("%02d-%02d-%02d",....); devrait marcher.
    N'oubliez pas de cliquer sur mais aussi sur si un commentaire vous a été utile !
    Et surtout

  11. #11
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 33
    Points : 15
    Points
    15
    Par défaut
    MERCI INFINIMENT

    j ai utilisé SimpleDateFormat (yyyy-MM-dd) mais le jour et le mois étaient affichés sur 1e seule position .
    mais à présent tout est réglé avec (%02d-%02d-%02d) c'est la solution que je cherchais
    encore merci

  12. #12
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    Non non SimpleDateFormat("yyyy-MM-dd") doit afficher les mois et jours avec deux chiffres. (je ne suis pas sur de bien saisir "1 seule position" ?)

    La doc officielle en cas de doute:
    http://docs.oracle.com/javase/7/docs...ateFormat.html

    Number: For formatting, the number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount. For parsing, the number of pattern letters is ignored unless it's needed to separate two adjacent fields.
    N'oubliez pas de cliquer sur mais aussi sur si un commentaire vous a été utile !
    Et surtout

  13. #13
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 33
    Points : 15
    Points
    15
    Par défaut
    il me affiche le jour et le mois en 1 chiffre (5 pas 05 ) je crois que le pb venait de "%d-%d-%d" mais bon là c réglé
    merci

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

Discussions similaires

  1. Problème date et graphique
    Par rob2-9 dans le forum Access
    Réponses: 4
    Dernier message: 14/08/2006, 12h41
  2. Problème Date access/asp
    Par buzz! dans le forum ASP
    Réponses: 16
    Dernier message: 08/08/2006, 14h53
  3. [Dates] problème date
    Par Le Rebel dans le forum Langage
    Réponses: 4
    Dernier message: 17/02/2006, 23h53
  4. [Dates] problème date
    Par masseur dans le forum Langage
    Réponses: 7
    Dernier message: 16/01/2006, 11h03
  5. [Access 2003] - Problème date dans requête
    Par Leesox dans le forum Access
    Réponses: 11
    Dernier message: 14/10/2005, 08h51

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