I am developing an android application using IntelliJ IDEA 11.1.2 and I need datepicker on my input form. However, when I insert it, IDEA gives “Missing class DatePicker” warning in the preview window and I launch application on the phone it crashes. If I remove datepicker element, application works properly.
I am using android 2.2 as a target platform and java 1.6 as java SDK.
Here’s source code of my form:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/l_main"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:text="Some text: "
android:layout_width="fill_parent"
android:textSize="@dimen/fnt_size"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/source"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="Some text: "
android:layout_width="fill_parent"
android:textSize="@dimen/fnt_size"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/destination"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="Some text: "
android:layout_width="fill_parent"
android:textSize="@dimen/fnt_size"
android:layout_height="wrap_content"
/>
<DatePicker
android:id="@+id/date"
android:endYear="2011"
android:startYear="2011"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/submitBtn"
android:text="Search"
android:layout_width="@dimen/btn_size"
android:textSize="@dimen/fnt_size"
android:layout_height="wrap_content" />
</LinearLayout>
How can I solve this problem?
UPDATE: I have filed bug report for this issue (Android <= 2.3).
So I was able to reproduce case that you have. Indeed IDEA signals that’s there’s some issue and app is crashing. Using Eclipse will not help (checked it) – Graphical Layout view in there will also signals that it cannot create
DatePickerobject.ROOT CAUSE
It occurs that the problem in your case is that
android:startYearandandroid:endYeardo not include current year on the device (range 2011-2011 does not include 2012 – current year).This is probably a bug in
DatePickerimplementation (prior to API 11) which tries to init the widget with current date regardless whether or notandroid:startYearandandroid:endYeardefine range that have current year within it.SOLUTION
Because you are using API level 9, there are no
android:minDateorandroid:maxDateproperties (introduced in API 11). So to restrict date picking to any range of years (workaround for the above mentioned bug), you can implement your ownOnDateChangedListener.Example code with comments: