我想提出一个布局内的另一个布局,但我这样做时,它relLayout.addView(squareLayout);
线如何将布局放入另一个布局?
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 7; j++) {
RelativeLayout relLayout = (RelativeLayout) findViewById(relIds[i][j]);
relLayout.removeAllViews();
RelativeLayout squareLayout = (RelativeLayout) findViewById(R.id.square);
relLayout.addView(squareLayout);
}
}
请告诉我,我应该怎么办给出NullPointerException
?
我们需要你的XML文件。另外,这是什么“relIds”?你应该使用LogCat来找出哪两个布局是空的。 – Klaus 2011-03-17 12:09:22
,因为它声明它在'relLayout.addView(squareLayout)'上给出'NullPointerException';'squareLayout应该为null。你有没有设置setContentView,是你的主布局的“方形”视图部分? – pankajagarwal 2011-03-17 13:48:30