Stack Overflow错误android?

时间:2011-08-26 10:14:24

标签: android stack-overflow

我的代码运行正常但突然间我再次运行代码时,它给了我堆栈溢出错误。以下是我的代码:HelloDatePickerActivity已经定义。

HelloDatePickerActivity daten=new HelloDatePickerActivity();
        static final int DATE_DIALOG_ID = 0;    
        Button mPickDate;
        TextView mDateDisplay;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.offline_screen);

    mPickDate=(Button)findViewById(R.id.pickDate);

        mPickDate.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                showDialog(DATE_DIALOG_ID); 
            }
        });        
    }
        @Override
        protected Dialog onCreateDialog(int id) {
            switch (id) {
            case DATE_DIALOG_ID:
                return new DatePickerDialog(this,
                            daten.mDateSetListener,
                            daten.mYear, daten.mMonth, daten.mDay);
            }
            return null;
        }         

}

Logcat是:

08-26 15:38:50.039: ERROR/AndroidRuntime(585): FATAL EXCEPTION: main
    08-26 15:38:50.039: ERROR/AndroidRuntime(585): java.lang.StackOverflowError
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at java.lang.Thread.currentThread(Thread.java:558)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at java.lang.ThreadLocal.get(ThreadLocal.java:53)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at android.os.Looper.myLooper(Looper.java:157)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at android.os.Handler.<init>(Handler.java:119)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at android.app.Activity.<init>(Activity.java:728)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:14)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerActivity.<init>(HelloDatePickerActivity.java:20)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.ACB_OnlineScreenActivity.<init>(ACB_OnlineScreenActivity.java:23)
    08-26 15:38:50.039: ERROR/AndroidRuntime(585):     at acb.xiynove.HelloDatePickerA

1 个答案:

答案 0 :(得分:2)

HelloDatePickerActivity daten=new HelloDatePickerActivity();

这是你的问题。想一想。

编辑:无论如何,你必须明白调用new Activity()是不好的编程习惯。不幸的是,我不能提供文件参考说明确切的事情。 Some relatively useful reference about creating new activities.