【问题标题】:java.lang.IllegalAccessError: tried to access method android.widget.LinearLayoutjava.lang.IllegalAccessError:试图访问方法 android.widget.LinearLayout
【发布时间】:2016-05-31 17:58:08
【问题描述】:
 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 元素,但出现错误,即,

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

谁能帮我解决。

【问题讨论】:

  • 为什么要调用onViewAdded()方法?

标签: java android


【解决方案1】:

换行

MainLayout.onViewAdded(ChildLayout);

MainLayout.addView(ChildLayout);

【讨论】:

    猜你喜欢
    • 2011-10-27
    • 2020-12-30
    • 1970-01-01
    • 2014-07-20
    • 2013-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-22
    相关资源
    最近更新 更多