title: Custom ToggleButton findViewById Null Pointer
body: <p>I have been trying to solve this problem for hours now and have exhausted all the obvious solutions.  I have a custom toggle button that works fine as long as I don't try to get it using findViewById</p>
  
  <p>Here is the relevant code:</p>
  
  <pre><code>public class WeekButton extends ToggleButton {
  
      private static int mWidth;
  
      public WeekButton(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      public WeekButton(Context context, AttributeSet attrs, int defStyle) {
          super(context, attrs, defStyle);
      }
      ...
  }
  </code></pre>
  
  <p>Here is the layout..</p>
  
  <pre><code>&lt;LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginBottom="8dp"
      android:gravity="center"
      android:orientation="horizontal"
      android:padding="5dp"&gt;
  
      &lt;org.myname.projetname.reminders.WeekButton.WeekButton
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/mondayToggleButton"
          style="@style/RecurrenceDayOfWeekStyle"
          android:textOff="  Mon"
          android:textOn="  Mon" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Exception occurs here..</p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.edit_reminder_activity);
          //This causes null pointer
          WeekButton weekButton = (WeekButton)findViewById(R.id.mondayToggleButton));
  }
  </code></pre>
  
  <p>Thanks for any help you can provide!</p>
  
  <p>SOLUTION: Turns out I forgot to instantiate the list I was adding the WeekButtons which made it look like the call to find id was working but it was.  Thank you everyone you tried to help.</p>