西蒙集成电路日期选取器对话框抛出android.view.InflateException:二进制X

2019-08-17 06:37发布

我使用的是西蒙的ICS日期选取器库( https://github.com/SimonVT在我的Android应用程序)。 我有一个日期按钮,如果我点击这个按钮,它会显示在对话框中的IC日期选择器。 我的问题是,如果我点击按钮,它不显示日期选择器对话框,但它显示了以下错误的:

03-02 10:46:59.521: E/AndroidRuntime(911): android.view.InflateException: Binary XML file line #20: Error inflating class net.simonvt.widget.DatePicker
03-02 10:46:59.521: E/AndroidRuntime(911):  at android.view.LayoutInflater.createView(LayoutInflater.java:606)
03-02 10:46:59.521: E/AndroidRuntime(911):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-02 10:46:59.521: E/AndroidRuntime(911):  at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
03-02 10:46:59.521: E/AndroidRuntime(911):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-02 10:46:59.521: E/AndroidRuntime(911):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-02 10:46:59.521: E/AndroidRuntime(911):  at net.simonvt.app.DatePickerDialog.<init>(DatePickerDialog.java:103)
03-02 10:46:59.521: E/AndroidRuntime(911):  at net.simonvt.app.DatePickerDialog.<init>(DatePickerDialog.java:74)



@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
        case START_DATE_PICKER_ID:
            mCalendar.setTimeInMillis(mStartMillis);
            year = mCalendar.get(Calendar.YEAR);
            monthOfYear = mCalendar.get(Calendar.MONTH);
            dayOfMonth = mCalendar.get(Calendar.DAY_OF_MONTH);
            return new DatePickerDialog(ListPillBoxActivity.this, startPillBoxDateListener,
                    year, monthOfYear, dayOfMonth);
        case END_DATE_PICKER_ID:
            mCalendar.setTimeInMillis(mEndMillis);
            year = mCalendar.get(Calendar.YEAR);
            monthOfYear = mCalendar.get(Calendar.MONTH);
            dayOfMonth = mCalendar.get(Calendar.DAY_OF_MONTH);
            return new DatePickerDialog(ListPillBoxActivity.this, endPillBoxDateListener, year,
                    monthOfYear, dayOfMonth);
    }

    return null;
}

对错误的两种情况下,以下行指出:

 return new DatePickerDialog(ListPillBoxActivity.this, startPillBoxDateListener,
                    year, monthOfYear, dayOfMonth);

每一个参数是否正确传递给datePickerDialog,但有一个问题,在充气对话框

任何帮助表示赞赏....

Answer 1:

我遇到了同样的问题。 解决的办法是三个项目添加到您的风格像DatePickerSamples:

<style name="SampleTheme" parent="@android:style/Theme">
    <item name="calendarViewStyle">@style/Widget.Holo.CalendarView</item>
    <item name="datePickerStyle">@style/Widget.Holo.DatePicker</item>
    <item name="numberPickerStyle">@style/NPWidget.Holo.NumberPicker</item>
</style>


Answer 2:

建立在什么@ham说,

加上几行为XML资源后:

<style name="SampleTheme" parent="@android:style/Theme">
    <item name="calendarViewStyle">@style/Widget.Holo.CalendarView</item>
    <item name="datePickerStyle">@style/Widget.Holo.DatePicker</item>
    <item name="numberPickerStyle">@style/NPWidget.Holo.NumberPicker</item>
</style>

有必要将此属性添加到您的application在AndroidManifest标签:

android:theme="@style/SampleTheme"


Answer 3:

也千万不要错过:

<!-- Copy one of these attributes to your own theme (choose either dark or light).
    <item name="numberPickerStyle">@style/NPWidget.Holo.NumberPicker</item>
    <item name="numberPickerStyle">@style/NPWidget.Holo.Light.NumberPicker</item>
-->


文章来源: Simon Ics Date Picker Dialog throws android.view.InflateException: Binary XML file line #20: Error inflating class net.simonvt.widget.DatePicker