生成APK后,日期选择器崩溃

时间:2019-01-18 12:38:37

标签: android datepicker permissions

我的应用在模拟器和财务设备上成功运行,但是在构建APK并将其安装到设备中后,当我打开日期选择器时,应用崩溃并停止。

    @SuppressLint("ValidFragment")
    class DatePickerFragment extends DialogFragment 
              implements DatePickerDialog.OnDateSetListener {

        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            // Use the current date as the default date in the picker
            final Calendar c = Calendar.getInstance();
            int year = c.get(Calendar.YEAR);
            int month = c.get(Calendar.MONTH);
            int day = c.get(Calendar.DAY_OF_MONTH);

            // Create a new instance of DatePickerDialog and return it
            return new DatePickerDialog(getActivity(), R.style.CustomDateTimeDialog, this, year, month, day);
        }

        public void onDateSet(DatePicker view, int year, int month, int day) {
            // Do something with the date chosen by the user
            String mese;
            switch(month+1){
                case 1: mese="Gennaio";dateEditText.setText(day+" "+mese+" "+year);break;
                case 2: mese="Febbraio";dateEditText.setText(day+" "+mese+" "+year);break;
                case 3: mese="Marzo";dateEditText.setText(day+" "+mese+" "+year);break;
                case 4: mese="Aprile";dateEditText.setText(day+" "+mese+" "+year);break;
                case 5: mese="Maggio";dateEditText.setText(day+" "+mese+" "+year);break;
                case 6: mese="Giugno";dateEditText.setText(day+" "+mese+" "+year);break;
                case 7: mese="Luglio";dateEditText.setText(day+" "+mese+" "+year);break;
                case 8: mese="Agosto";dateEditText.setText(day+" "+mese+" "+year);break;
                case 9: mese="Settembre";dateEditText.setText(day+" "+mese+" "+year);break;
                case 10: mese="Ottobre";dateEditText.setText(day+" "+mese+" "+year);break;
                case 11: mese="Novembre";dateEditText.setText(day+" "+mese+" "+year);break;
                case 12: mese="Dicembre";dateEditText.setText(day+" "+mese+" "+year);break;
            }
        }

    }

0 个答案:

没有答案