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 conversion date


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 conversion date
    j'ai un pb au niveau de la conversion en date d'une variable (var) que je récupére de la bdd (sqlite)
    voila le code de mon activité
    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.sql.Date;
    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;
    
    public class RechercherTransactions extends Activity {
    	Calendar c;
    	
    	TextView essai;
    	String dat;
    	java.util.Date d1;
    	java.util.Date d2;
    	java.util.Date d3;
    	long dd1;
    	long dd2;
    	long dd3;
    	
    	String agec_de_historique; 
    	public final static String AGECONS="bb";
    	  public final  static String AGEC="a";
    	
    	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);
    			
    	     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() {
                // Month is 0 based so add 1
    	        editToDate.setText( String.format("%d-%d-%d",toYear,toMonth + 1,toDay));
    	}
    	private void updateFromDateDisplay() {
            // Month is 0 based so add 1
            editFromDate.setText( String.format("%d-%d-%d",fromYear,fromMonth + 1,fromDay));
    }
    	 
    	public void searchTransactions(View v) {
    		 Database dbUser = new Database(RechercherTransactions.this);
    			dbUser.open();
    		
    		 chaine1 = cpte1.getText().toString();
    		 chaine2 = editFromDate.getText().toString();//date de deut
    		 chaine3 = editToDate.getText().toString();//date de fin
    		
    				
    		
    			  
    	   	   
    			
    		
    		
    		  
    	  
    		 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    		
    		 String kk=format.format(c.getTime());
    
    		  if(chaine1.length() > 0 && chaine2.length() > 0 && chaine3.length() > 0)
    				{
    			  dat = dbUser.recuperer_date_trans(chaine1);//je recupere la date de la bdd
    			  dbUser.close();
    				 try {
    					 d1=format.parse(chaine2);//convresion au format date de la 1ere date
    					  d2=format.parse(chaine3);//convresion au format date de la 2ere date
    					  d3 = format.parse(dat);//convresion au format date de la date recupérée de labdd
    				} catch (ParseException e1) {
    					// TODO Auto-generated catch block
    					e1.printStackTrace();
    				}
    				
    
    				
    	    	   
    	    		
    		    	 //conversion en secondes des dates
    	    	 
    				   dd1=d1.getTime();//fromdate
    				  dd2=d2.getTime();//todate
    				  dd3= d3.getTime();//date de la bdd
    				  
    					if(dd2>=dd1)
    					{
    						
    						dbUser.open();
      			
    						
      			 
      			 
      			
    						
    					
    						if(dbUser.Auth_compte(chaine1) ) 
    					      {	
    							
    					    
    					    	
    							
    							if( dd2>=dd3 )
    							{
    							 
    						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 numero de compte n'est pas le votre", Toast.LENGTH_LONG).show();
    						
    							
    						
    				}
    								
    								
    									else Toast.makeText(RechercherTransactions.this,"aucune trans", 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);
    		}
    
    }
    j ai une erreur
    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
     
    05-13 11:55:13.000: E/AndroidRuntime(23919): java.lang.IllegalStateException: Could not execute method of the activity
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at android.view.View$1.onClick(View.java:2072)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at android.view.View.performClick(View.java:2408)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at android.view.View$PerformClick.run(View.java:8816)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at android.os.Handler.handleCallback(Handler.java:587)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at android.os.Handler.dispatchMessage(Handler.java:92)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at android.os.Looper.loop(Looper.java:123)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at android.app.ActivityThread.main(ActivityThread.java:4627)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at java.lang.reflect.Method.invokeNative(Native Method)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at java.lang.reflect.Method.invoke(Method.java:521)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at dalvik.system.NativeStart.main(Native Method)
    05-13 11:55:13.000: E/AndroidRuntime(23919): Caused by: java.lang.reflect.InvocationTargetException
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at com.example.mobilebanque.RechercherTransactions.searchTransactions(RechercherTransactions.java:187)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at java.lang.reflect.Method.invokeNative(Native Method)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at java.lang.reflect.Method.invoke(Method.java:521)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at android.view.View$1.onClick(View.java:2067)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	... 11 more
    05-13 11:55:13.000: E/AndroidRuntime(23919): Caused by: java.lang.NullPointerException
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1201)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	at java.text.DateFormat.parse(DateFormat.java:642)
    05-13 11:55:13.000: E/AndroidRuntime(23919): 	... 15 more
    cette erreur intervient qd je saisi un numero qi nest pas au client,donc là ou il est sensé m'executer :if( dbUser.transfert( agec_de_historique,chaine1)==true) et mafficher nest pas le votre
    dnc je ne sais pas ou est l'erreur au niveau de la conversion???

  2. #2
    Membre chevronné
    Avatar de eulbobo
    Homme Profil pro
    Développeur Java
    Inscrit en
    Novembre 2003
    Messages
    786
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Novembre 2003
    Messages : 786
    Points : 1 993
    Points
    1 993
    Par défaut
    05-13 11:55:13.000: E/AndroidRuntime(23919): Caused by: java.lang.NullPointerException
    05-13 11:55:13.000: E/AndroidRuntime(23919): at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1201)
    A vue de nez, je dirais que ton objet "dat" doit être null
    Je ne suis pas mort, j'ai du travail !

  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
    j 'ai affiché la date recupérée dans "dat" dans un textview et la date est affichée dnc la valeur n'est pas nulle

  4. #4
    Membre chevronné
    Avatar de eulbobo
    Homme Profil pro
    Développeur Java
    Inscrit en
    Novembre 2003
    Messages
    786
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Novembre 2003
    Messages : 786
    Points : 1 993
    Points
    1 993
    Par défaut
    dat = dbUser.recuperer_date_trans(chaine1);//je recupere la date de la bdd
    On n'a pas le code derrière cette méthode, mais potentiellement à cet endroit, la variable dat peut être nulle (selon ce qui se passe dessous)
    Je ne suis pas mort, j'ai du travail !

  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
    g réglé mon pb , j'ai géré le cas ou dat n est pas null avec
    if (dat!=null){...}

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

Discussions similaires

  1. Problème conversion date vb.net access 2010
    Par ismaiila dans le forum VB.NET
    Réponses: 2
    Dernier message: 24/04/2014, 10h49
  2. problème conversion date en format yyMMdd
    Par CosaNostra dans le forum Collection et Stream
    Réponses: 2
    Dernier message: 08/06/2010, 13h41
  3. Problème conversion date
    Par pit007 dans le forum ASP.NET
    Réponses: 6
    Dernier message: 20/11/2007, 17h12
  4. problème conversion date en chaîne
    Par fakhita dans le forum Langage
    Réponses: 6
    Dernier message: 12/07/2007, 14h16
  5. Problème conversion date
    Par mat.M dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 30/03/2004, 15h05

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