我开发Android应用程序,不幸的是在一些旧设备中它无法正常工作...我只是在我的TextView上设置了点击监听器,并在我的日期选择器代码中显示了datePicker Dialogue,只是将日期设置为相同的textView。
在我的活动中:
Feild_Age.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DialogFragment fragment = new DatePickerFragment();
fragment.show(getFragmentManager(), "Date Picker");
}
});
我的日期选择器片段代码.... 所有这些代码都在我的单一活动中。
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:主要流程: com.jeffysmak.blooddonationpk,PID:2755 java.lang.NoClassDefFoundError:android.icu.util.Calendar at com.jeffysmak.blooddonationpk.DonorProfile $ DatePickerFragment.onCreateDialog(DonorProfile.java:252) 在 android.app.DialogFragment.getLayoutInflater(DialogFragment.java:398) 在 android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890) 在 android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062) 在android.app.BackStackRecord.run(BackStackRecord.java:684)at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447) 在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) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)at dalvik.system.NativeStart.main(原生方法)
答案 0 :(得分:2)
java.lang.NoClassDefFoundError:android.icu.util.Calendar
刚刚将导入从android.icu.util.Calendar
更改为java.util.Calendar