title: Android Studio. AddRule Null pointer Exception
body: <p>I've got a problem with the addRule function in Android Studio.
  I loop trough an Array list of Languages.
  For every language I add a Textview. After I added 1 textview, the next Textview should be aligned under the first one. I get a NullpointerException at the addrule line. Is my way of setting and getting the Id of the view wrong? Sorry for incomplete Xml. The whole Xml code is inside a Relative Layout.</p>
  
  <pre><code>private void listLanguages() {
  
      RelativeLayout relativelayout = (RelativeLayout) findViewById(R.id.addrole);
      int e;
      for (int i=0; i &lt; languages.size(); i++) {
          TextView textview = new TextView(AddRole.this);
          if (i &gt; 0) {
          e = i-1;
              RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) textview.getLayoutParams();
              lp.addRule(RelativeLayout.BELOW,e);
              textview.setLayoutParams(lp);
          }
          textview.setText(languages.get(i));
          textview.setId(i);
          relativelayout.addView(textview);
  
  }
  </code></pre>
  
  <p>XML:</p>
  
  <pre><code>&lt;include
      layout = "@layout/esnmis"
      android:id="@+id/esnmis"
      android:layout_width="match_parent"
      android:layout_height="55dp"&gt;
  &lt;/include&gt;
  
  &lt;TextView
      android:layout_width="250dp"
      android:layout_height="wrap_content"
      android:inputType="textPersonName"
      android:layout_below="@+id/esnmis"
      android:textSize="30dp"
      android:gravity="center"
      android:id="@+id/description"
      android:layout_marginTop="4dp"
      android:layout_centerHorizontal="true" /&gt;
  
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_below="@id/description"
      android:id="@+id/addrole"&gt;
  
  &lt;/RelativeLayout&gt;
  
  &lt;Button
      android:text=""
      android:textSize="20dp"
      android:textAllCaps="false"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/insert"
      android:layout_below="@+id/addrole"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="5dp" /&gt;
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>E/AndroidRuntime: FATAL EXCEPTION: main
                      Process: com.example.obo.database, PID: 11262
                      java.lang.NullPointerException: Attempt to read from field 'int android.view.ViewGroup$LayoutParams.width' on a null object reference
                          at android.view.ViewGroup$LayoutParams.(ViewGroup.java:7346)
                          at android.view.ViewGroup$MarginLayoutParams.(ViewGroup.java:7643)
                          at android.widget.RelativeLayout$LayoutParams.(RelativeLayout.java:1345)
                          at com.example.obo.database.AddRole.listLanguages(AddRole.java:107)
                          at com.example.obo.database.AddRole.access$300(AddRole.java:28)
                          at com.example.obo.database.AddRole$1$1.run(AddRole.java:79)
                          at android.os.Handler.handleCallback(Handler.java:739)
                          at android.os.Handler.dispatchMessage(Handler.java:95)
                          at android.os.Looper.loop(Looper.java:148)
                          at android.app.ActivityThread.main(ActivityThread.java:7331)
                          at java.lang.reflect.Method.invoke(Native Method)
                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)</p>
  </blockquote>