DialogはfindViewByIdを使用して空のポインタ異常を報告する


問題の説明
Dialogの作成が完了したら、DialogのTextViewの値を変更して、ポインタ異常を報告します.
    Dialog dialog = new CustomDialog(context);             //   Dialog
    TextView textView=dialog.findViewById(R.id.textView1); //           
    textView.setText("    UI  ")
    dialog.show();

問題の原因Dialog#findViewByIdソースコードの表示
   /**
     * Finds a child view with the given identifier. Returns null if the
     * specified child view does not exist or the dialog has not yet been fully
     * created (for example, via {@link #show()} or {@link #create()}).
     *
     * @param id the identifier of the view to find
     * @return The view with the given id or null.
     */
    public View findViewById(int id) {
        return mWindow.findViewById(id);
    }

注記は、dialogがまだ完全に作成されていない場合(show()またはcreate()メソッドが呼び出されていない場合)は、nullに戻ります.
問題解決
コード実行順序を調整し、Dialog#show()メソッドを呼び出してからDialog#findViewByIdメソッドを呼び出す
    Dialog dialog = new CustomDialog(context);             //   Dialog
    dialog.show();
    TextView textView=dialog.findViewById(R.id.textView1); 
    textView.setText("    UI  ")