应用程序崩溃而没有编译错误(xxx已停止)

时间:2019-09-18 16:29:12

标签: android android-studio

在构建版本为24的情况下使用Nexus S5可以使应用正常运行。

我切换到使用版本23,因此可以使用File Device Explorer检查我的SQLite数据库文件。

当我在编译时获得以下输出后,当我切换回版本24时,它开始崩溃:

  

使用或覆盖已贬值的API

我注释掉了我用来初始化时间的setTime()方法,因为它包含了两个折旧方法(setCurrentHoursetCurrentTime)。

不幸的是,它仍然给我编译信息:

  

使用或覆盖已贬值的API


    public static final String EXTRA_DATE = "com.bignerdranch.android.criminalintent.time";
    private static final String ARG_DATE = "time";
    private static final String TAG = "TimePickerFragment";
    private TimePicker mTimePicker;

    public static TimePickerFragment newInstance(Date date) {
        Bundle args = new Bundle();
        args.putSerializable(ARG_DATE, date);

        TimePickerFragment fragment = new TimePickerFragment();
        fragment.setArguments(args); // This adds the 'extra'.
        return fragment;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        View v = LayoutInflater.from(getActivity())
                .inflate(R.layout.dialog_time, null);

        mTimePicker = (TimePicker) v.findViewById(R.id.dialog_time_picker);

        return new AlertDialog.Builder(getActivity())
                .setView(v)
                .setTitle(R.string.time_picker_title)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                    {   // TimePicker lacks an initializer, unlike DatePicker.
                        Date date = (Date) getArguments().getSerializable(ARG_DATE);
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(date);
                        int initMinute = calendar.get(Calendar.MINUTE);
                        int initHour = calendar.get(Calendar.HOUR);
                        //setTime(initHour, initMinute);
                    }

                    /*private void setTime(int hour, int minute) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                            mTimePicker.setHour(hour);
                            mTimePicker.setMinute(minute);
                        } else {
                            mTimePicker.setCurrentHour(hour);
                            mTimePicker.setCurrentMinute(minute);
                        }
                    }*/


                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Date date = (Date) getArguments().getSerializable(ARG_DATE);
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(date);

                        int year = calendar.get(Calendar.YEAR);
                        int month = calendar.get(Calendar.MONTH);
                        int day = calendar.get(Calendar.DAY_OF_MONTH);
                        int minute = mTimePicker.getCurrentMinute();
                        int hour = mTimePicker.getCurrentHour();
                        Date newDate = new GregorianCalendar(year, month, day, hour, minute).getTime();
                        sendResult(Activity.RESULT_OK, newDate);
                    }

                    private void sendResult(int resultCode, Date date) {

                        if (getTargetFragment() == null) {
                            return;
                        }

                        Intent intent = new Intent();
                        intent.putExtra(EXTRA_DATE, date);

                        getTargetFragment()
                                .onActivityResult(getTargetRequestCode(), resultCode, intent);
                    }

                })
                .create();
    }

}

我希望它不会崩溃,并且我怀疑它与使用模拟Android早期版本的模拟器时的最新更新有关。

0 个答案:

没有答案