java.lang.IllegalAccessError:尝试访问方法android.widget.LinearLayout

时间:2016-02-19 08:27:20

标签: java android

 MainLayout=(LinearLayout) getActivity().findViewById(R.id.LinLaySub);
        for(int k=0;k<Dist_cat.length;k++) {
            Cursor c = db.getQueryResult("select * from prod_mas where sub_name='" + Dist_catname[k] + "'");   
           for (int i = 0; i < c.getCount(); i++) {
                c.moveToFirst();
                ChildLayout=new LinearLayout(getActivity());
                ChildLayout.setWeightSum(100);
                ChildLayout.setOrientation(LinearLayout.HORIZONTAL);
                ChildLayout.setBackgroundColor(getResources().getColor(R.color.sublay));
                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
                ChildLayout.setId(i);
                edit_phy = new EditText(getActivity());
                edit_phyAll.add(edit_phy);
                edit_phy.setBackgroundResource(R.color.black);
                edit_phy.setId(+i + 1);
                edit_phy.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT));
                ChildLayout.addView(edit_phy);

                edit_trn = new EditText(getActivity());
                edit_trnAll.add(edit_trn);
                edit_trn.setBackgroundResource(R.color.black);
                edit_trn.setId(+i + 2);
                edit_trn.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT));
                ChildLayout.addView(edit_trn);

                MainLayout.onViewAdded(ChildLayout);
                c.moveToNext();
            }

        }

我试图以编程方式添加一些ui-element,但我收到错误,即

  

java.lang.IllegalAccessError:尝试访问方法   android.widget.LinearLayout.onViewAdded:

任何人都可以帮我解决。

1 个答案:

答案 0 :(得分:1)

更改行

MainLayout.onViewAdded(ChildLayout);

MainLayout.addView(ChildLayout);