开发者

How to put layout inside another layout?

开发者 https://www.devze.com 2023-02-17 15:12 出处:网络
I want to put a layout inside another layout but when I do this it gives NullPointerException on relLayout.addView(squareLayout); line

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

0

精彩评论

暂无评论...
验证码 换一张
取 消