异常:java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

原因:View是不能同时有两个parent的。

builder.setView(linearLayout);

其中linearLayout不要在Activity的onCreate()中赋值。

改为在dialog中赋值就能解决此异常。

LinearLayout linearLayout = (LinearLayout)findViewById(R.id.help);
AlertDialog.Builder builder = new Builder(activity);
builder.setView(linearLayout);
builder.create().show();

 

posted on 2013-04-23 21:07  燃烧的CO2  阅读(867)  评论(0编辑  收藏  举报