title: Button button = findViewById(R.id.button) always resolves to null in Android
body: <p>I'm new to Android development, so pardon my ignorance.</p>
  <p><code>findViewById</code> of a button I added always resolves to <code>null</code>. Hence if I try to <code>setonClickListener</code> it fails the whole Activity.</p>
  <p><strong>MainActivity:</strong></p>
  <pre><code>public class MainActivity extends ActionBarActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          if (savedInstanceState == null) {
              getSupportFragmentManager().beginTransaction()
                      .add(R.id.container, new PlaceholderFragment())
                      .commit();
          }
  
          Button buttonClick = (Button) findViewById(R.id.button);
          buttonClick.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  onButtonClick((Button) view);
              }
  
          });
  
      }
  
      public void onButtonClick(Button view) {
          TextView textHello = (TextView) findViewById(R.id.textView);
          textHello.setText(&quot;Clicked !!!&quot;);
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
          if (id == R.id.action_settings) {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  
      /**
       * A placeholder fragment containing a simple view.
       */
      public static class PlaceholderFragment extends Fragment {
  
          public PlaceholderFragment() {
          }
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                  Bundle savedInstanceState) {
              View rootView = inflater.inflate(R.layout.fragment_main, container, false);
              return rootView;
          }
      }
  
  }
  </code></pre>
  <p><strong>activity_main.xml</strong></p>
  <pre><code>&lt;FrameLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  android:id=&quot;@+id/container&quot;
  android:layout_width=&quot;match_parent&quot;
  android:layout_height=&quot;match_parent&quot;
  tools:context=&quot;com.pluralsight.activitylifecycle.MainActivity&quot;
  tools:ignore=&quot;MergeRootFrame&quot; /&gt;
  </code></pre>
  <p><strong>fragment_main.xml</strong></p>
  <pre><code>&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  android:layout_width=&quot;match_parent&quot;
  android:layout_height=&quot;match_parent&quot;
  android:paddingLeft=&quot;@dimen/activity_horizontal_margin&quot;
  android:paddingRight=&quot;@dimen/activity_horizontal_margin&quot;
  android:paddingTop=&quot;@dimen/activity_vertical_margin&quot;
  android:paddingBottom=&quot;@dimen/activity_vertical_margin&quot;
  tools:context=&quot;com.pluralsight.activitylifecycle.MainActivity$PlaceholderFragment&quot;&gt;
  
  &lt;TextView
      android:text=&quot;@string/hello_world&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:id=&quot;@+id/textView&quot; /&gt;
  
  &lt;Button
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:text=&quot;@string/buttonClick&quot;
      android:id=&quot;@+id/button&quot;
      android:layout_below=&quot;@+id/textView&quot;
      android:layout_alignParentRight=&quot;true&quot;
      android:layout_alignParentEnd=&quot;true&quot;
      android:layout_marginRight=&quot;54dp&quot; /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>