title: How can I add an existing xml layout to a layout that created by code
body: <p>I have an xml like this</p>
  
  <pre><code>&lt;android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/SlidingPanel"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;LinearLayout
          android:layout_width="240dp"
          android:layout_height="match_parent"
          android:layout_gravity="left"&gt;
  
          &lt;ListView
              android:id="@+id/MenuList"
              android:layout_width="match_parent"
              android:layout_height="match_parent" &gt;
          &lt;/ListView&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_gravity="right"
          android:background="#101010"
          android:orientation="vertical" &gt;
  
  
          &lt;Button
              android:id="@+id/button1"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:text="Button"
               /&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/android.support.v4.widget.SlidingPaneLayout&gt;
  </code></pre>
  
  <p>Now I want to add it to my main layout, which is a framelayout I created by code. Here is what I did:</p>
  
  <pre><code>SlidingPaneLayout mSlidingPanel;
          Button bt;
          View slide_menu;
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              slide_menu = mInflater.inflate(R.layout.activity_main, null);
  
  //CREATE FRAMELAYOUT HERE
              FrameLayout fr = new FrameLayout(this);
              fr.setId(1);        
              ViewGroup scene1 = (ViewGroup) findViewById(fr.getId());
              FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
  
              scene1.addView(slide_menu, lp);
              //////////////
          mSlidingPanel = (SlidingPaneLayout) findViewById(R.id.SlidingPanel);
          mMenuList = (ListView) findViewById(R.id.MenuList);
          appImage = (ImageView)findViewById(android.R.id.home);
          TitleText = (TextView)findViewById(android.R.id.title);
          bt = (Button)findViewById(R.id.button1);
  
          for(int i = 0;i&lt;imgID.length;i++){
              CreateObject ob = new CreateObject(imgID[i], titleContext[i], null );
              mObject.add(ob);
          }
          mListViewAdapter = new CreateListViewAdapter(this, mObject);
          mMenuList.setAdapter(mListViewAdapter);
  
          mSlidingPanel.setPanelSlideListener(panelListener);
          mSlidingPanel.setParallaxDistance(200);
  
  /*
          mListViewAdapter.notifyDataSetChanged();
  */
          bt.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  if(mSlidingPanel.isOpen()){
                      mSlidingPanel.closePane();
                  }
                  else{
                      mSlidingPanel.openPane();
                  }
              }
          });
  
  // SET CONTENTVIEW HERE
               setContentView(scene1,lp);
  </code></pre>
  
  <p>But I always get </p>
  
  <blockquote>
    <p>NullPointer error.</p>
  </blockquote>
  
  <p>I think the problem is caused by findviewByID, because in description it says that: "Finds a view that was identified by the id attribute from the XML that was processed in onCreate", so it will always be null, but I don't know how to correct it.</p>