2011-08-17 23 views
0

私のアプリケーションは、保存ダイアログボックスまたはキャンセルダイアログボックスを表示します。ユーザーが[保存]をクリックすると、新しいダイアログに編集テキスト、日付ボタン、保存ボタンが表示されます。ユーザーが日付をクリックするとDateダイアログが表示されます。しかし、私はInvocationTargetExceptionを取得する日付ボタンをクリックします。これをどうすれば解決できますか?Androidのダイアログからダイアログを表示する方法は?

Dialog d = new Dialog(CameraView.this, R.style.Dialog);    
         d.requestWindowFeature(Window.FEATURE_NO_TITLE); 
         d.setContentView(R.layout.img_info); 
         loadDate(); 
         d.setCancelable(true); 

LoadDateメソッドこの

private void loadDate(){ 
     // 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 (this method is below) 
     updateDisplay(); 

    } 
    private void updateDisplay() { 
     mDateDisplay.setText(
      new StringBuilder() 
        // Month is 0 based so add 1 
        .append(mMonth + 1).append("-") 
        .append(mDay).append("-") 
        .append(mYear).append(" ")); 
    } 

    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(); 
      } 
     }; 

    @Override 
    protected Dialog onCreateDialog(int id) { 
     switch (id) { 
     case DATE_DIALOG_ID: 
      return new DatePickerDialog(this, 
         mDateSetListener, 
         mYear, mMonth, mDay); 
     } 
     return null; 
    } 

答えて

0

ように私はあなたがnull InvocationTargetExceptionたびonCreateDialogリターンを打つと信じています。

私はこの修正により、super.onCreateDialog(id)に電話していることを確認していると思います。

@Override 
protected Dialog onCreateDialog(int id) { 
    switch (id) { 
    case DATE_DIALOG_ID: 
     return new DatePickerDialog(this, 
        mDateSetListener, 
        mYear, mMonth, mDay); 
    } 
    return super.onCreateDialog(id); 
} 

あなたは例外の前にいわゆるメソッド見ることができますので、おそらくあなたのコードにいくつかのログを追加する必要がありますあなたに起こっている正確に何確認します。

関連する問題