Android 日期选择器错误
Android date picker error
我开发了 android 应用程序,但不幸的是,在一些旧设备上它无法正常工作...我只是在我的 TextView 上设置了点击监听器,它显示了 datePicker 对话,在我的日期选择器代码中,只是设置了日期到相同的 textView .
在我的 activity 中:
Feild_Age.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DialogFragment fragment = new DatePickerFragment();
fragment.show(getFragmentManager(), "Date Picker");
}
});
我的日期选择器片段代码....
所有这些代码都在我的单曲 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.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)
请有人帮忙....谢谢:)
java.lang.NoClassDefFoundError: android.icu.util.Calendar
刚刚将导入从 android.icu.util.Calendar
更改为 java.util.Calendar
来源:Android Studio stack=java.lang.NoClassDefFoundError: Failed resolution of: Landroid/icu/util/Calendar;
我开发了 android 应用程序,但不幸的是,在一些旧设备上它无法正常工作...我只是在我的 TextView 上设置了点击监听器,它显示了 datePicker 对话,在我的日期选择器代码中,只是设置了日期到相同的 textView .
在我的 activity 中:
Feild_Age.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DialogFragment fragment = new DatePickerFragment();
fragment.show(getFragmentManager(), "Date Picker");
}
});
我的日期选择器片段代码.... 所有这些代码都在我的单曲 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.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)
请有人帮忙....谢谢:)
java.lang.NoClassDefFoundError: android.icu.util.Calendar
刚刚将导入从 android.icu.util.Calendar
更改为 java.util.Calendar
来源:Android Studio stack=java.lang.NoClassDefFoundError: Failed resolution of: Landroid/icu/util/Calendar;