2011-08-26 66 views
0

我的代碼運行良好,但突然當我再次運行代碼時,它給了我堆棧溢出錯誤。以下是我的代碼:HelloDatePickerActivity已被定義。Stack Overflow錯誤android?

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 

回答

2
HelloDatePickerActivity daten=new HelloDatePickerActivity(); 

這是你的問題。想想看。

編輯:無論如何,你必須明白,調用new Activity()是不好的編程習慣。不幸的是,我無法提供文檔參考信息說明確切的事情。 Some relatively useful reference about creating new activities.

+0

它以前運行良好與此代碼呢! – ross

+0

HelloDatePickerActivity已經被定義 – ross

+0

@ross:在你尚未初始化ACB_OlineScreenActivity之前呢?只是猜測;) – ZeissS

相關問題