Calendar date = Calendar.getInstance();
new DatePickerDialog(Ledger_Dinner_Detail.this,
// 绑定监听器
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker dp, int year,
int month, int dayOfMonth) {
StringBuilder temp = new StringBuilder()
.append(year)
.append("-")
.append((month + 1) < 10 ? "0"
+ (month + 1) : (month + 1))
.append("-")
.append(dayOfMonth < 10 ? "0"
+ dayOfMonth : dayOfMonth);
String date = temp.toString();
DinnerDate.setText(date);
}
}
// 设置初始日期
, date.get(Calendar.YEAR), date.get(Calendar.MONTH), date
.get(Calendar.DAY_OF_MONTH)).show();
为什么Debug运行的时候报错,其他正常。
开发环境android studio
错误代码:
android.view.InflateException: Binary XML file line #20: Error inflating class android.widget.DatePicker
at android.view.LayoutInflater.createView(LayoutInflater.java:623)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:672)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.inflate(LayoutInflater.java:472)
at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.app.DatePickerDialog.<init>(DatePickerDialog.java:108)
at android.app.DatePickerDialog.<init>(DatePickerDialog.java:79)