title: Android custom component works fine at runtime, but doesn't work at design time
body: <p>I am doing my first steps in Android development.
   In the meantime I am trying to create a custom component (for testing purposes) that will later be used on an Activity.</p>
  
  <p>Here's the code for ClearableEditText.java:</p>
  
  <pre><code>import android.content.Context;
  import android.util.AttributeSet;
  import android.view.LayoutInflater;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.LinearLayout;
  
  public class ClearableEditText extends LinearLayout {
  
      private EditText textField;
      private Button button;
  
      public ClearableEditText(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
  
      @Override
      protected void onFinishInflate() {
          super.onFinishInflate();
  
          LayoutInflater.from(this.getContext()).inflate(R.layout.clearable_text,  this);
  
          setupViewItems();
      }
  
      private void setupViewItems() {
          // TODO Auto-generated constructor stub
  
  
          this.textField = (EditText) findViewById(R.id.editText1);
          this.button = (Button) findViewById(R.id.button1);
  
          this.textField.setText("Hello World 123");
      }    
  }
  </code></pre>
  
  <p>And here's its layout XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;EditText
          android:id="@+id/editText1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:ems="10" &gt;
  
          &lt;requestFocus /&gt;
      &lt;/EditText&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"        
          android:text="Button" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>This is the XML layout code for the activity that will integrate the component:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".SegundaActivity" &gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_centerVertical="true"
          android:text="@string/ativity2_text" /&gt;
  
      &lt;EditText
          android:id="@+id/editText1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/textView1"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="33dp"
          android:ems="10" &gt;
  
          &lt;requestFocus /&gt;
      &lt;/EditText&gt;
  
      &lt;com.example.aplicacaoteste.ClearableEditText
          android:id="@+id/newComponent"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/editText1"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="33dp"
          android:ems="10" &gt;
      &lt;/com.example.aplicacaoteste.ClearableEditText&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>When I run the app, the component works fine. Nonetheless, as soon as I switch to the Graphical Layout of my Activity, I get the following error message:</p>
  
  <pre><code>java.lang.NullPointerException
  Exception details are logged in Window &gt; Show View &gt; Error Log
  
  java.lang.NullPointerException
      at com.example.aplicacaoteste.ClearableEditText.setupViewItems(ClearableEditText.java:36)
      at com.example.aplicacaoteste.ClearableEditText.onFinishInflate(ClearableEditText.java:26)
      at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:754)
      at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
      at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:749)
      at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:372)
  </code></pre>
  
  <p>I have no clue about what's going on in here. Can anyone help me out?</p>