How to put layout inside another layout?
I want to put a layout inside another layout but when I do this it gives NullPointerException
on relLayout.addView(squareLayout);
line
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);
}
}
Please tell me what should I do?
relLayout
is not null while accessing removeAllViews()
method. So either findViewById()
or another thread would have set null to relLayout
instance.
improper use of relIds[][] without initialization could have also caused Null pointer exception
精彩评论