I have the exact the problem.  I simply cut and post the tutorial from
the Android Developer site.

Here is my main.xml and java code.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView android:id="@+id/dateDisplay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""/>

    <Button android:id="@+id/pickDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Change the date"/>

</LinearLayout>



import android.app.Activity;
import android.app.DatePickerDialog;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Button;
import android.widget.DatePicker;
import android.view.View;

import java.util.Calendar;


public class HelloDatePicker extends Activity
{
    private TextView mDateDisplay;
    private Button mPickDate;

    private int mYear;
    private int mMonth;
    private int mDay;

    static final int DATE_DIALOG_ID = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // capture our View elements
        mDateDisplay = (TextView) findViewById(R.id.dateDisplay);
        mPickDate = (Button) findViewById(R.id.pickDate);

        // add a click listener to the button
        mPickDate.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                showDialog(DATE_DIALOG_ID);
            }
        });

        // get the current date
        final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);

        // display the current date
        updateDisplay();
    }


    // updates the date we display in the TextView
    private void updateDisplay() {
        mDateDisplay.setText(
            new StringBuilder()
                    // Month is 0 based so add 1
                    .append(mMonth + 1).append("-")
                    .append(mDay).append("-")
                    .append(mYear).append(" "));
    }
    // the callback received when the user "sets" the date in the
dialog
    private DatePickerDialog.OnDateSetListener mDateSetListener =
            new DatePickerDialog.OnDateSetListener() {

                public void onDateSet(DatePicker view, int year,
                                      int monthOfYear, int dayOfMonth)
{
                    mYear = year;
                    mMonth = monthOfYear;
                    mDay = dayOfMonth;
                    updateDisplay();
                }
            };
}


Here is the log from catlog:


/ActivityManager(   52): Starting activity: Intent
{ act=android.intent.action.MAIN cat=
[android.intent.category.LAUNCHER] flg=0x10200000
cmp=com.chesterxgchen.example1/.HelloDatePicker }
I/ActivityManager(   52): Start proc com.chesterxgchen.example1 for
activity com.chesterxgchen.example1/.HelloDatePicker: pid=259
uid=10024 gids={1015}
I/ActivityManager(   52): Displayed activity
com.chesterxgchen.example1/.HelloDatePicker: 1047 ms (total 1047 ms)
D/dalvikvm(  100): GC freed 112 objects / 4896 bytes in 110ms
I/dalvikvm(  259): threadid=7: reacting to signal 3
E/dalvikvm(  259): Unable to open stack trace file '/data/anr/
traces.txt': Permission denied
D/AndroidRuntime(  259): Shutting down VM
W/dalvikvm(  259): threadid=3: thread exiting with uncaught exception
(group=0x4001b188)
E/AndroidRuntime(  259): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime(  259): java.lang.IllegalArgumentException:
Activity#onCreateDialog did not create a dialog for id 0
E/AndroidRuntime(  259):        at android.app.Activity.createDialog
(Activity.java:871)
E/AndroidRuntime(  259):        at android.app.Activity.showDialog
(Activity.java:2483)
E/AndroidRuntime(  259):        at com.chesterxgchen.example1.HelloDatePicker
$1.onClick(HelloDatePicker.java:37)
E/AndroidRuntime(  259):        at android.view.View.performClick(View.java:
2364)
E/AndroidRuntime(  259):        at android.view.View.onTouchEvent(View.java:
4179)
E/AndroidRuntime(  259):        at android.widget.TextView.onTouchEvent
(TextView.java:6540)
E/AndroidRuntime(  259):        at android.view.View.dispatchTouchEvent
(View.java:3709)
E/AndroidRuntime(  259):        at android.view.ViewGroup.dispatchTouchEvent
(ViewGroup.java:884)
E/AndroidRuntime(  259):        at android.view.ViewGroup.dispatchTouchEvent
(ViewGroup.java:884)
E/AndroidRuntime(  259):        at android.view.ViewGroup.dispatchTouchEvent
(ViewGroup.java:884)
E/AndroidRuntime(  259):        at android.view.ViewGroup.dispatchTouchEvent
(ViewGroup.java:884)
E/AndroidRuntime(  259):        at
com.android.internal.policy.impl.PhoneWindow
$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
E/AndroidRuntime(  259):        at
com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent
(PhoneWindow.java:1107)
E/AndroidRuntime(  259):        at android.app.Activity.dispatchTouchEvent
(Activity.java:2061)
E/AndroidRuntime(  259):        at
com.android.internal.policy.impl.PhoneWindow
$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
E/AndroidRuntime(  259):        at android.view.ViewRoot.handleMessage
(ViewRoot.java:1691)
E/AndroidRuntime(  259):        at android.os.Handler.dispatchMessage
(Handler.java:99)
E/AndroidRuntime(  259):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  259):        at android.app.ActivityThread.main
(ActivityThread.java:4363)
E/AndroidRuntime(  259):        at java.lang.reflect.Method.invokeNative
(Native Method)
E/AndroidRuntime(  259):        at java.lang.reflect.Method.invoke
(Method.java:521)
E/AndroidRuntime(  259):        at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(  259):        at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:618)
E/AndroidRuntime(  259):        at dalvik.system.NativeStart.main(Native
Method)
I/Process (   52): Sending signal. PID: 259 SIG: 3
I/dalvikvm(  259): threadid=7: reacting to signal 3
E/dalvikvm(  259): Unable to open stack trace file '/data/anr/
traces.txt': Permission denied
I/dalvikvm(  259): threadid=7: reacting to signal 3
E/dalvikvm(  259): Unable to open stack trace file '/data/anr/
traces.txt': Permission denied
I/dalvikvm(  259): threadid=7: reacting to signal 3
E/dalvikvm(  259): Unable to open stack trace file '/data/anr/
traces.txt': Permission denied
I/Process (  259): Sending signal. PID: 259 SIG: 9
I/WindowManager(   52): WIN DEATH: Window{43d97fd8
com.chesterxgchen.example1/com.chesterxgchen.example1.HelloDatePicker
paused=false}
I/ActivityManager(   52): Process com.chesterxgchen.example1 (pid 259)
has died.



Any ideas ?


On Nov 20 2009, 11:09 pm, Justin Anderson <janderson....@gmail.com>
wrote:
> I'm pretty sure this isn't the cause of the problem, but I am curious why
> your XML file has your button set to not be clickable...  Seems odd since
> you are trying to click that buttong...
> ----------------------------------------------------------------------
> There are only 10 types of people in the world...
> Those who know binary and those who don't.
> ----------------------------------------------------------------------
>
> On Tue, Nov 3, 2009 at 7:29 PM, 大方 <yangfang_1...@163.com> wrote:
> > Hello,guys!
> > I encountered a problem while I run the application below.The UI can
> > appear in the emulator screen normally,but while I click the button
> > the bug appears.Below I attach the source and the logcat:
>
> > the source code:
>
> > HelloDatePicker.java
>
> > package HelloDatePicker.pkg;
> > import java.util.Calendar;
> > import android.app.Activity;
> > import android.app.DatePickerDialog;
> > import android.app.Dialog;
> > import android.os.Bundle;
> > import android.view.View;
> > import android.widget.Button;
> > import android.widget.DatePicker;
> > import android.widget.TextView;
>
> > public class HelloDatePickerAct extends Activity {
> >    /** Called when the activity is first created. */
> >        private TextView mDateDisplay;
> >        private Button mPickDate;
> >        private int mYear;
> >        private int mMonth;
> >        private int mDay;
> >        static final int DATE_DIALOG_ID=0x00000000;
>
> >   �...@override
> >    public void onCreate(Bundle savedInstanceState) {
> >        super.onCreate(savedInstanceState);
> >        setContentView(R.layout.main);
>
> >        //capture our View elements
> >        mDateDisplay=(TextView)findViewById(R.id.DateDisplay);
> >        mPickDate=(Button)findViewById(R.id.PickDate);
>
> >        //get the current date
> >        final Calendar c=Calendar.getInstance();
> >        mYear=c.get(Calendar.YEAR);
> >        mMonth=c.get(Calendar.MONTH);
> >        mDay=c.get(Calendar.DAY_OF_MONTH);
>
> >        //display the current date
> >        updateDisplay();
>
> >        //add a click listener to the button
> >        mPickDate.setOnClickListener(new View.OnClickListener() {
>
> >                       �...@override
> >                        public void onClick(View v) {
> >                                // TODO Auto-generated method stub
> >                                showDialog(DATE_DIALOG_ID);
> >                        }
> >                });
> >    }
>
> >    protected Dialog OnCreateDialog(int id){
> >        switch(id){
> >        case DATE_DIALOG_ID:
> >                return new DatePickerDialog
> > (this,mDateSetListener,mYear,mMonth,mDay);
> >        }
> >        return null;
> >        }
> > //updates the date we display in the TextView
> >    private void updateDisplay()
> > {
> >        mDateDisplay.setText(new StringBuilder()
> >        //Month is 0 based so add 1
> >        .append(mMonth+1).append("-")
> >        .append(mDay).append("-")
> >        .append(mYear).append(" "));
> > }
>
> >  // the callback received when the user "sets" the date in the dialog
> >    private DatePickerDialog.OnDateSetListener mDateSetListener =
> >            new DatePickerDialog.OnDateSetListener() {
>
> >                public void onDateSet(DatePicker view, int year,
> >                                      int monthOfYear, int dayOfMonth)
> > {
> >                    mYear = year;
> >                    mMonth = monthOfYear;
> >                    mDay = dayOfMonth;
> >                    updateDisplay();
> >                }
> >            };
>
> > }
>
> > main.xml
>
> > <?xml version="1.0" encoding="utf-8"?>
>
> > <LinearLayout android:id="@+id/LinearLayout01"
> > android:layout_width="fill_parent" android:layout_height="fill_parent"
> > xmlns:android="http://schemas.android.com/apk/res/android";
> > android:orientation="vertical">
> > <TextView android:layout_width="wrap_content"
> > android:layout_height="wrap_content" android:id="@+id/DateDisplay"
> > android:editable="false"></TextView>
> > <Button android:layout_width="wrap_content"
> > android:layout_height="wrap_content" android:id="@+id/PickDate"
> > android:text="Change the date" android:clickable="false"></Button>
> > </LinearLayout>
>
> > I  debug step by step and while debugging at the breakpoint
> > onClick,the logcat  appears as below:
> > 11-04 01:15:03.152: ERROR/AndroidRuntime(809): Uncaught handler:
> > thread main exiting due to uncaught exception
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):
> > java.lang.IllegalArgumentException: Activity#onCreateDialog did not
> > create a dialog for id 0
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.app.Activity.createDialog(Activity.java:869)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.app.Activity.showDialog(Activity.java:2408)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > HelloDatePicker.pkg.HelloDatePickerAct$2.onClick
> > (HelloDatePickerAct.java:49)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.view.View.performClick(View.java:2344)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.view.View.onTouchEvent(View.java:4133)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.widget.TextView.onTouchEvent(TextView.java:6504)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.view.View.dispatchTouchEvent(View.java:3672)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > com.android.internal.policy.impl.PhoneWindow
> > $DecorView.superDispatchTouchEvent(PhoneWindow.java:1712)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent
> > (PhoneWindow.java:1202)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.app.Activity.dispatchTouchEvent(Activity.java:1987)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > com.android.internal.policy.impl.PhoneWindow
> > $DecorView.dispatchTouchEvent(PhoneWindow.java:1696)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.view.ViewRoot.handleMessage(ViewRoot.java:1658)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.os.Handler.dispatchMessage(Handler.java:99)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.os.Looper.loop(Looper.java:123)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > android.app.ActivityThread.main(ActivityThread.java:4203)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > java.lang.reflect.Method.invokeNative(Native Method)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > java.lang.reflect.Method.invoke(Method.java:521)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
> > (ZygoteInit.java:791)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
> > 11-04 01:15:03.180: ERROR/AndroidRuntime(809):     at
> > dalvik.system.NativeStart.main(Native Method)
> > 11-04 01:15:03.220: ERROR/dalvikvm(809): Unable to open stack trace
> > file '/data/anr/traces.txt': Permission denied
>
> > From the logcat,I guess it is the ID problem,but I don't know how to
> > use it correctly and I can't get any help from the sdk docs,please
> > help!
>
> > I have another question about '11-04 01:15:03.220: ERROR/dalvikvm
> > (809): Unable to open stack trace file '/data/anr/traces.txt':
> > Permission denied' ,how to do with it?
>
> > 3Q!
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Beginners" group.
> > To post to this group, send email to android-beginners@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com>
> > For more options, visit this group at
> >http://groups.google.com/group/android-beginners?hl=en
-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to