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 :

application android probleme


Sujet :

Android

  1. #1
    Futur Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2015
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2015
    Messages : 6
    Points : 6
    Points
    6
    Par défaut application android probleme
    mon application s'arrête si j'ajoute quelque lignes de code
    ceci est mon code éxecutable:
    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
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    import java.lang.reflect.Array;
    import java.util.Calendar;
     
    import android.content.Context;
    import android.content.res.Resources;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.Rect;
    import android.graphics.drawable.Drawable;
    import android.util.AttributeSet;
    import android.util.MonthDisplayHelper;
    import android.view.MotionEvent;
    import android.widget.ImageView;
     
    public class CalendarView extends ImageView {
        private static int WEEK_TOP_MARGIN = 74;
        private static int WEEK_LEFT_MARGIN = 40;
        private static int CELL_WIDTH = 50;
        private static int CELL_HEIGH = 48;
        private static int CELL_MARGIN_TOP = 92;
        private static int CELL_MARGIN_LEFT = 39;
        private static float CELL_TEXT_SIZE;
     
    	private static final String TAG = "CalendarView"; 
    	private Calendar mRightNow = null;
        private Drawable mWeekTitle = null;
        private Cell mToday = null;
        private Cell[][] mCells = new Cell[6][7];
        private OnCellTouchListener mOnCellTouchListener = null;
        MonthDisplayHelper mHelper;
        Drawable mDecoration = null;
    	int mPeriod ;
         int mCycle ;
          int  mYear;
          int  mMonth;
          int  mDay;
    	int clBlood;
    	int clBlue;
    	int clFertile;
    	int clGreen;
    	int clLtBlue;
    	int clLtGreen;
    	int clLtOrange;
    	int clLtRed;
    	int clMagenta;
    	int clNotFertile;
    	int clOrange;
    	int clRed;
    	boolean dayInThisMonth;
    	int pickedDayOfMonth;
        Calendar givenDate;
    	Calendar pickedDate;
    	class _calendar {
    		public int day;
    		public boolean thisMonth;
    		public _calendar(int d, boolean b) {
    			day = d;
    			thisMonth = b;
    		}
    		public _calendar(CalendarView calendarView, int d) {
    			this(d, false);
    		}
    	};
    	public interface OnCellTouchListener {
        	public void onTouch(Cell cell);
        }
     
    	public CalendarView(Context context) {
    		this(context, null);
    	}
     
    	public CalendarView(Context context, AttributeSet attrs) {
    		this(context, attrs, 0);
    	}
     
    	public CalendarView(Context context, AttributeSet attrs, int defStyle) {
    		super(context, attrs, defStyle);
    		mDecoration = context.getResources().getDrawable(R.drawable.today);
    		initCalendarView();
    		this.mRightNow = null;
    		this.mWeekTitle = null;
    		this.mToday = null;
    		this.mCells = (Cell[][]) Array.newInstance(Cell.class, new int[]{6, 7});
    		this.mOnCellTouchListener = null;
    		this.mDecoration = null;
    		this.mPeriod = 29;
    		this.mCycle = 5;
    		this.mYear = -1;
    		this.mMonth = -1;
    		this.mDay = -1;
    		this.clBlood = 0xffff0000;
    		this.clFertile = Color.rgb(0, 155, 0); //vert foncé//
    		this.clNotFertile = Color.rgb(220, 220,220); //gris//
    		this.clLtRed = Color.rgb(255, 100, 100); //rose//
    		this.clRed = Color.rgb(255, 55, 55); //rouge//
    		this.clLtGreen = Color.rgb(100, 255, 100); //vert//
    		this.clGreen = Color.rgb(55, 255, 55); //vert//
    		this.clLtBlue = -65281;
    		this.clBlue = Color.rgb(55, 55, 255); //bleu//
    		this.clMagenta = Color.rgb(255, 55, 255); //violet//
    		this.pickedDate = Calendar.getInstance();
    		this.givenDate = Calendar.getInstance();
    		initCalendarView();
    	}
     
    	private void initCalendarView() {
    		mRightNow = Calendar.getInstance();
    		// prepare static vars
    		Resources res = getResources();
    		WEEK_TOP_MARGIN  = (int) res.getDimension(R.dimen.week_top_margin);
    		WEEK_LEFT_MARGIN = (int) res.getDimension(R.dimen.week_left_margin);
     
    		CELL_WIDTH = (int) res.getDimension(R.dimen.cell_width);
    		CELL_HEIGH = (int) res.getDimension(R.dimen.cell_heigh);
    		CELL_MARGIN_TOP = (int) res.getDimension(R.dimen.cell_margin_top);
    		CELL_MARGIN_LEFT = (int) res.getDimension(R.dimen.cell_margin_left);
     
    		CELL_TEXT_SIZE = res.getDimension(R.dimen.cell_text_size);
     
     
    		// set background
    		setImageResource(R.drawable.background);
    		mWeekTitle = res.getDrawable(R.drawable.calendar_week);
     
    		mHelper = new MonthDisplayHelper(mRightNow.get(Calendar.YEAR), mRightNow.get(Calendar.MONTH));
     
        }
     
    	private void initCells() {
     
    	    _calendar tmp[][] = (_calendar[][]) Array.newInstance (_calendar.class , new int[]{6, 7});
     
    	    for(int i=0; i<tmp.length; i++) {
    			int n[] = mHelper.getDigitsForRow(i);
    			for (int d = 0; d < n.length; d++) {
    				if (mHelper.isWithinCurrentMonth(i, d)) {
    					tmp[i][d] = new _calendar(n[d], true);
    				} else {
    					tmp[i][d] = new _calendar(this, n[d]);
    				}
    			}
     
    		}
    		if (this.dayInThisMonth) {
    			this.pickedDate.set(this.mHelper.getYear(), this.mHelper.getMonth(), this.pickedDayOfMonth);
    		} else {
    			int i2;
    			int i3 = this.mYear >= 0 ? 1 : 0;
    			if (this.mMonth >= 0) {
    				i2 = 1;
    			} else {
    				i2 = 0;
    			}
    			i2 &= i3;
    			if (this.mDay >= 0) {
    				i3 = 1;
    			} else {
    				i3 = 0;
    			}
    			if ((i3 & i2) != 0) {
    				this.pickedDate.set(this.mYear, this.mMonth, this.mDay);
    			}
    		}
     
    	    Calendar today = Calendar.getInstance();
    	    int thisDay = 0;
    	    mToday = null;
    	    if(mHelper.getYear()==today.get(Calendar.YEAR) && mHelper.getMonth()==today.get(Calendar.MONTH)) {
    	    	thisDay = today.get(Calendar.DAY_OF_MONTH);
    	    }
    		// build cells
     
    		Rect Bound = new Rect(CELL_MARGIN_LEFT, CELL_MARGIN_TOP, CELL_WIDTH+CELL_MARGIN_LEFT, CELL_HEIGH+CELL_MARGIN_TOP);
    		int week = 0;
    		while (week < this.mCells.length) {
    			int day = 0;
    			while (day < this.mCells[week].length) {
    				if (tmp[week][day].thisMonth) {
    					if(day==0) {
    						mCells[week][day] = new WhiteCell(tmp[week][day].day, new Rect(Bound), CELL_TEXT_SIZE, 0xffff0000,0xff888888,0);
    					}
    					else {
    						mCells[week][day] = new WhiteCell(tmp[week][day].day, new Rect(Bound), CELL_TEXT_SIZE, 0xff000000,0xff888888,0);
    					}
    				} else {
    					mCells[week][day] = new GrayCell(tmp[week][day].day, new Rect(Bound), CELL_TEXT_SIZE, 0xcecece, 0xffffffff);
    				}
     
    				Bound.offset(CELL_WIDTH, 0); // move to next column 
     
    				// get today
    				if(tmp[week][day].day==thisDay && tmp[week][day].thisMonth) {
    					mToday = mCells[week][day];
     
    					mDecoration.setBounds(mToday.getBound());
    				}
    				day++;
    			}
    			Bound.offset(0, CELL_HEIGH); // move to next row and first column
    			Bound.left = CELL_MARGIN_LEFT;
    			Bound.right = CELL_MARGIN_LEFT+CELL_WIDTH;
    			week++;
    		}		
    	}
     
    	@Override
    	public void onLayout(boolean changed, int left, int top, int right, int bottom) {
    		Rect re = getDrawable().getBounds();
    		WEEK_LEFT_MARGIN = CELL_MARGIN_LEFT = (right-left - re.width()) / 2;
    		mWeekTitle.setBounds(WEEK_LEFT_MARGIN, WEEK_TOP_MARGIN, WEEK_LEFT_MARGIN+mWeekTitle.getMinimumWidth(), WEEK_TOP_MARGIN+mWeekTitle.getMinimumHeight());
    		initCells();
    		super.onLayout(changed, left, top, right, bottom);
    	}
     
        public void setTimeInMillis(long milliseconds) {
        	mRightNow.setTimeInMillis(milliseconds);
        	initCells();
        	this.invalidate();
        }
     
        public int getYear() {
        	return mHelper.getYear();
        }
     
        public int getMonth() {
        	return mHelper.getMonth();
        }
     
        public void nextMonth() {
        	mHelper.nextMonth();
        	initCells();
        	invalidate();
        }
     
        public void previousMonth() {
        	mHelper.previousMonth();
        	initCells();
        	invalidate();
        }
     
        public boolean firstDay(int day) {
        	return day==1;
        }
     
        public boolean lastDay(int day) {
        	return mHelper.getNumberOfDaysInMonth()==day;
        }
     
        public void goToday() {
        	Calendar cal = Calendar.getInstance();
        	mHelper = new MonthDisplayHelper(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH));
        	initCells();
        	invalidate();
        }
     
        public Calendar getDate() {
        	return mRightNow;
        }
     
        @Override
        public boolean onTouchEvent(MotionEvent event) {
        	if(mOnCellTouchListener!=null){
    	    	for(Cell[] week : mCells) {
    				for(Cell day : week) {
    					if(day.hitTest((int)event.getX(), (int)event.getY())) {
    						mOnCellTouchListener.onTouch(day);
    					}						
    				}
    			}
        	}
        	return super.onTouchEvent(event);
        }
     
        public void setOnCellTouchListener(OnCellTouchListener p) {
    		mOnCellTouchListener = p;
    	}
     
    	@Override
    	protected void onDraw(Canvas canvas) {
    		// draw background
    		super.onDraw(canvas);
    		mWeekTitle.draw(canvas);
     
    		// draw cells
    		for(Cell[] week : mCells) {
    			for(Cell day : week) {
    				day.draw(canvas);			
    			}
    		}
     
    		// draw today
    		if(mDecoration!=null && mToday!=null) {
    			mDecoration.draw(canvas);
    		}
    	}
     
    	public class GrayCell extends Cell {
    		public GrayCell(int dayOfMon, Rect rect, float s, int txtCol, int bkgCol) {
    			super(dayOfMon, rect, s,bkgCol,txtCol);
    			this.mPaint.setStyle(Paint.Style.FILL);
    			CalendarView.this.invalidate();
    		}
    	}
     
    	private class WhiteCell extends Cell {
    		public WhiteCell(int dayOfMon, Rect rect, float s, int txtCol, int bkgCol, int stroke) {
    			super(dayOfMon, rect, s,bkgCol,txtCol);
    			this.mStroke = stroke;
    			this.mPaint.setStyle(Paint.Style.FILL);
    		}
    	}
     
    	public long DateDifference(Calendar selectedDay, Calendar givenDay) {
    		Calendar cal1 = Calendar.getInstance();
    		Calendar cal2 = Calendar.getInstance();
    		cal1.set(2016, 12, 30);
    		cal2.set(2017, 5, 3);
    		long diff = givenDay.getTimeInMillis() - selectedDay.getTimeInMillis();
    		if (diff < 0) {
    			diff -= 3600000;
    		}
    		long diffSeconds = diff / 1000;
    		long diffMinutes = diff / 60000;
    		long diffHours = diff / 3600000;
    		long diffDays = diff / 86400000;
    		System.out.println("In milliseconds: " + diff + " milliseconds.");
    		System.out.println("In seconds: " + diffSeconds + " seconds.");
    		System.out.println("In minutes: " + diffMinutes + " minutes.");
    		System.out.println("In hours: " + diffHours + " hours.");
    		System.out.println("In days: " + diffDays + " days.");
    		return diffDays;
    	}
     
    	public void setParams(int period, int bleeding, int year, int month, int day) {
    		this.mPeriod = period;
    		this.mCycle = bleeding;
    		this.mYear = year;
    		this.mMonth = month;
    		this.mDay = day;
    	}
     
    }

    Si j'ajout ses ligne de code au niveau de //build cells// l'application devient non exécutable

    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
    // build cells
     
    		Rect Bound = new Rect(CELL_MARGIN_LEFT, CELL_MARGIN_TOP, CELL_WIDTH+CELL_MARGIN_LEFT, CELL_HEIGH+CELL_MARGIN_TOP);
    		int week = 0;
    		while (week < this.mCells.length) {
    			int day = 0;
    			while (day < this.mCells[week].length) {
    				if (tmp[week][day].thisMonth) {
     
    this.givenDate.set(this.mHelper.getYear(), this.mHelper.getMonth(), tmp[week][day].day);
                        long dayDiff = DateDifference(this.pickedDate, this.givenDate);
                        if (this.mPeriod == 0) {
                            this.mPeriod = 29;
                        }
                        if (this.mCycle == 0) {
                            this.mCycle = 5;
                        }
                        long diff = (dayDiff + ((long) (this.mPeriod * 3))) % ((long) this.mPeriod);
                        int stroke = 0;
                        int bkgCol = this.clLtOrange;
                        if (((long) (this.mPeriod - 18)) <= diff && diff <= ((long) (this.mPeriod - 12))) {
                            bkgCol = this.clLtGreen;
                        }
                        if (1 <= diff && diff <= ((long) (this.mCycle - 1))) {
                            bkgCol = this.clLtRed;
                        }
                        if (diff == ((long) (this.mPeriod - 14))) {
                            bkgCol = this.clLtGreen;
                            stroke = this.clGreen;
                        }
                        if (diff == 0) {
                            bkgCol = this.clMagenta;
                            stroke = this.clBlue;
                        }
    if(day==0) {
    mCells[week][day] = new WhiteCell(tmp[week][day].day, new Rect(Bound), CELL_TEXT_SIZE, 0xffff0000,0xff888888,0);
    					}
    					else {
    						mCells[week][day] = new WhiteCell(tmp[week][day].day, new Rect(Bound), CELL_TEXT_SIZE, 0xff000000,0xff888888,0);
    					}
    				} else {
    					mCells[week][day] = new GrayCell(tmp[week][day].day, new Rect(Bound), CELL_TEXT_SIZE, 0xcecece, 0xffffffff);
    				}
     
    				Bound.offset(CELL_WIDTH, 0); // move to next column 
     
    				// get today
    				if(tmp[week][day].day==thisDay && tmp[week][day].thisMonth) {
    					mToday = mCells[week][day];
     
    					mDecoration.setBounds(mToday.getBound());
    				}
    				day++;
    			}
    			Bound.offset(0, CELL_HEIGH); // move to next row and first column
    			Bound.left = CELL_MARGIN_LEFT;
    			Bound.right = CELL_MARGIN_LEFT+CELL_WIDTH;
    			week++;
    		}		
    	}

  2. #2
    Modérateur
    Avatar de grunk
    Homme Profil pro
    Lead dév - Architecte
    Inscrit en
    Août 2003
    Messages
    6 691
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Lead dév - Architecte
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2003
    Messages : 6 691
    Points : 20 222
    Points
    20 222
    Par défaut
    Bonjour,

    tout d'abord coller 400 lignes de codes et espérer que quelqu'un mettent le nez dedans c'est un peu utopique
    Essai de limiter ton extrait de code à la partie réellement intéressante.

    Si j'ajout ses ligne de code au niveau de //build cells// l'application devient non exécutable
    Quels sont les message d'erreur ? Que veux dire non exécutable ?
    Pry Framework php5 | N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #3
    Futur Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2015
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2015
    Messages : 6
    Points : 6
    Points
    6
    Par défaut
    je veux colorés des évents sur le calendrier ce pour cela j'ajout les des conditions ces conditions entraînent le blocage de l'application. je n'est pas eu des message d'erreur seulement lors de l'exécution l'emulateur montre un message "Calendar has sttoped"
    c'est le résultat de premier code
    Nom : Sans titre.png
Affichages : 392
Taille : 180,2 Ko
    Si j'ajout les code des ligne j'ai:
    Nom : aaaa.png
Affichages : 259
Taille : 164,8 Ko

  4. #4
    Modérateur
    Avatar de grunk
    Homme Profil pro
    Lead dév - Architecte
    Inscrit en
    Août 2003
    Messages
    6 691
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Lead dév - Architecte
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2003
    Messages : 6 691
    Points : 20 222
    Points
    20 222
    Par défaut
    Tu clic sur android monitor en bas de ta fenêtre android studio et tu auras le logcat qui affichera des message d'erreur. La base du debugage ...
    Pry Framework php5 | N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  5. #5
    Membre extrêmement actif
    Profil pro
    Développeur
    Inscrit en
    Mars 2012
    Messages
    1 969
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Mars 2012
    Messages : 1 969
    Points : 3 375
    Points
    3 375
    Par défaut
    Ajoute des try..catch à ton code.
    A la moindre erreur ça va exploser
    Si la réponse vous a aidé, pensez à cliquer sur +1

Discussions similaires

  1. [WM20] Probleme de generation applications android
    Par wilfried97 dans le forum Windev Mobile
    Réponses: 2
    Dernier message: 25/01/2017, 11h01
  2. [WM20] Probleme lors de la generation de mon application android
    Par alisaid.s dans le forum Windev Mobile
    Réponses: 5
    Dernier message: 24/05/2016, 12h10
  3. Probleme d'exécution d'application Android
    Par Douaaghof dans le forum Android
    Réponses: 1
    Dernier message: 27/07/2015, 19h53
  4. probleme de gradle dans l'application android studio
    Par Douaaghof dans le forum Android Studio
    Réponses: 0
    Dernier message: 15/07/2015, 23h41
  5. Probleme connexion application android vers bdd mysql
    Par Meian dans le forum API standards et tierces
    Réponses: 3
    Dernier message: 07/02/2014, 23h22

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