title: Android - Controls resolve to null
body: <p>I'm writing a decimal time converter for someone, and I am trying to use findViewById to access some of my controls.  So, I assign each of them, and then I assign an onclick listener to a button(btnConvert).  When I assign the listener, the app crashes due to the fact that btnConvert is null.  I have read into this, but I haven't found a working solution yet.  Please refer to my code below</p>
  
  <p>MainActivity.java:</p>
  
  <pre><code>package com.alex_justi.dec2time;
  
  import android.app.Activity;
  import android.app.ActionBar;
  import android.app.AlertDialog;
  import android.app.Fragment;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  import android.os.Build;
  
  public class MainActivity extends Activity {
  static EditText inDec;
  static Button btnConvert;
  static TextView outHours;
  static TextView outMinutes;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      if (savedInstanceState == null) {
          getFragmentManager().beginTransaction()
                  .add(R.id.container, new PlaceholderFragment())
                  .commit();
      }
  }
  
  /**
   * 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);
  
          inDec = (EditText)rootView.findViewById(R.id.dec);
          btnConvert = (Button)rootView.findViewById(R.id.convert);
          outHours = (TextView)rootView.findViewById(R.id.hours);
          outMinutes = (TextView)findViewById(R.id.minutes);
  
          return rootView;
      }
  }
  
  }
  </code></pre>
  
  <p>fragment_main.xml:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/layout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="com.alex_justi.dec2time.MainActivity$PlaceholderFragment" &gt;
  
  &lt;TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:text="Decimal Time" /&gt;
  
  &lt;EditText
      android:id="@+id/dec"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignParentRight="true"
      android:layout_below="@+id/textView1"
      android:ems="10"
      android:inputType="numberDecimal" &gt;
  
      &lt;requestFocus /&gt;
  &lt;/EditText&gt;
  
  &lt;Button
      android:id="@+id/convert"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignParentRight="true"
      android:layout_below="@+id/dec"
      android:text="Convert" /&gt;
  
  &lt;TextView
      android:id="@+id/minutes"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignParentRight="true"
      android:layout_below="@+id/hours"
      android:layout_marginTop="15dp"
      android:text="Minutes: "
      android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
  &lt;TextView
      android:id="@+id/hours"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignParentRight="true"
      android:layout_below="@+id/convert"
      android:text="Hours: "
      android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>