-1

i get

java.lang.NoSuchMethodError: android.app.DatePickerDialog.getDatePicker

this exception, when i use my DatePickerDialog on android 2.3.3. I know that getDatePicker() is available from 11 api, but all other methods available from api 1.

How can I resolve this problem? I read this,but it isn't work.

dpdBegin = new DatePickerDialog(this,
                datePickerListener, c.get(Calendar.YEAR), c.get(Calendar.MONTH),    c.get(Calendar.DAY_OF_MONTH));

//exception on this line       
tvPeriodFrom.setText(
                (prepareDate(dpdBegin.getDatePicker().getDayOfMonth())) + "-" + prepareDate(dpdBegin.getDatePicker().getMonth() + 1) +
                        "-" + dpdBegin.getDatePicker().getYear());   

 dpdBegin = new DatePickerDialog(this,
                datePickerListener, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));

    //Set dates to textViews
tvPeriodFrom.setText(
            (prepareDate(dpdBegin.getDatePicker().getDayOfMonth())) + "-" + prepareDate(dpdBegin.getDatePicker().getMonth() + 1) +
                    "-" + dpdBegin.getDatePicker().getYear());

In log is

    04-21 06:49:57.833: ERROR/AndroidRuntime(399): FATAL EXCEPTION: main
    java.lang.NoSuchMethodError: android.app.DatePickerDialog.getDatePicker
    at ua.khuta.mobilereception.EventsActivity.onCreate(EventsActivity.java:88)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3683)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    at dalvik.system.NativeStart.main(Native Method)
Community
  • 1
  • 1
Kostya Khuta
  • 1,846
  • 6
  • 26
  • 48

1 Answers1

0

If you want to obtain the date selected in the date picker you can use this code

Button bt_setdate=(Button) findViewById(R.id.bt_setdate);
bt_setdate.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            showDialog(DATE_DIALOG_ID);
            // get the current date

        }
    });

and outside onCreate()

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DATE_DIALOG_ID:
        // set date picker as current date
        return new DatePickerDialog(this, datePickerListener, 
                year, month,day);
    }
    return null;
}

private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {

    // when dialog box is closed, below method will be called.
    public void onDateSet(DatePicker view, int selectedYear,
            int selectedMonth, int selectedDay) {
        year = selectedYear;
        month = selectedMonth;
        day = selectedDay;
        String selmonth=cm.getMonth(month);

        bookingdate=String.valueOf(year)+"-"+String.valueOf(month)+"-"+String.valueOf(day);

    }
};

bookingdate contains the date that is selected.. and add this to your layout

<DatePicker
    android:id="@+id/dpResult"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:visibility="gone"/>
Lal
  • 14,726
  • 4
  • 45
  • 70