0
votes

i develop android app and unfortunately in some old devices it is not working ... i just set click listener on my TextView and which show datePicker Dialogue and in my date picker code, just setting the date to same textView .

in my activity :

Feild_Age.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DialogFragment fragment = new DatePickerFragment();
                fragment.show(getFragmentManager(), "Date Picker");
            }
        });

my code for date picker fragment .... all this code is in my single activity.

public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {


        @RequiresApi(api = Build.VERSION_CODES.N)
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            final Calendar calendar = Calendar.getInstance();
            int YEAR = calendar.get(Calendar.YEAR);
            int MONTH = calendar.get(Calendar.MONTH);
            int DAY = calendar.get(Calendar.DAY_OF_MONTH);

            DatePickerDialog DPD = new DatePickerDialog(getActivity(), android.app.AlertDialog.THEME_DEVICE_DEFAULT_DARK, this, YEAR, MONTH, DAY);

            return DPD;
        }

        @RequiresApi(api = Build.VERSION_CODES.N)
        @Override
        public void onDateSet(DatePicker datePicker, int YEAR, int MONTH, int DAY) {

//            TextView textView
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(0);
            calendar.set(YEAR, MONTH, DAY, 0, 0, 0);
            Date date = calendar.getTime();


            DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US);
            String forMatedDate = dateFormat.format(date);
            TextView Feild_Age = (TextView) getActivity().findViewById(R.id.age_of_user);
            Feild_Age.setText(forMatedDate);
            if (!Feild_Age.getText().toString().trim().equals("SELECT YOUR AGE")) {
                TextView dobb = (TextView) getActivity().findViewById(R.id.year_ofDOB);
                dobb.setText(String.valueOf(YEAR));
            }
        }
    }

logcat

08-21 22:40:47.015 2755-2755/com.jeffysmak.blooddonationpk E/AndroidRuntime: FATAL EXCEPTION: main Process: com.jeffysmak.blooddonationpk, PID: 2755 java.lang.NoClassDefFoundError: android.icu.util.Calendar at com.jeffysmak.blooddonationpk.DonorProfile$DatePickerFragment.onCreateDialog(DonorProfile.java:252) at android.app.DialogFragment.getLayoutInflater(DialogFragment.java:398) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062) at android.app.BackStackRecord.run(BackStackRecord.java:684) at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447) at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5045) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)

kindly some one help .... thanks :)

enter image description here

1
i edited my post with logcat... check :)Saif Ur Rehman
thanksssss man :D really thanks it worked...Saif Ur Rehman

1 Answers

2
votes

java.lang.NoClassDefFoundError: android.icu.util.Calendar

Just changed the import from android.icu.util.Calendar to java.util.Calendar

Source : Android Studio stack=java.lang.NoClassDefFoundError: Failed resolution of: Landroid/icu/util/Calendar;