我知道很多人问这个问题,但我不确定我的问题的解决方案是相同的。孩子已经有家长
我的代码是:
package com.example.goo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
public class Calendrier extends Activity{
LinearLayout linear;
TextView text;
ScrollView SV;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SV = new ScrollView(this);
linear = new LinearLayout(this);
linear.setOrientation(LinearLayout.VERTICAL);
text = new TextView(this);
text.setText("This is an example for the Bright Hub !");
SV.addView(linear);
linear.addView(text);
setContentView(linear);
}
}
和错误是:
致:java.lang.IllegalStateException:指定的孩子已经有一个父。您必须先调用子对象的父对象的removeView()。
的setContentView(线性); => setContentView(SV) – jimpanzer
谢谢,它的工作原理! – user1965878
我也发布了一个答案,如果我的评论可以帮助你,请接受和upvote我的答案。 – jimpanzer