由于错误信息是:java.lang.IllegalArgumentException: No view found for id 0x7f05003c (com.example.layouttest:id/container) for fragment PlaceholderFragment{我感觉错误不在现在楼主贴出的代码上,可能在  
setContentView(llpage);
之后中代码中。
能否再将之后代码贴出一些?

解决方案 »

  1.   

    再找其他原因,你定位错误了,可能在你的fragment里
      

  2.   

    你这代码是在fragment里写的吗,我在activity里贴了你的代码没有问题嘿
      

  3.   

     java.lang.IllegalArgumentException: No view found for id 0x7f05003c
    这句说的很清楚了!
      

  4.   

    如果是写在fragment里的,而且非要new的方式添加,可这么写,测试过,没问题,注意点生命周期
    public class MyFragment extends Fragment{

    private LinearLayout llpage;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
    llpage = new LinearLayout(getActivity());
            llpage.setLayoutParams(new LinearLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            llpage.setOrientation(LinearLayout.VERTICAL);
            // 创建TextView对象
            TextView mTextView = new TextView(getActivity());
            // 设置文字
            mTextView.setText("hello world");
     
            LinearLayout.LayoutParams mLayoutParams = new LinearLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
     
            // 在父类布局中添加它,及布局样式
            llpage.addView(mTextView, mLayoutParams);
    return llpage;
    }
    }