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, 大方 <[email protected]> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-beginners%[email protected]>
> 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.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to