Null Exception error while retrieving array of child views
<p>I have level1.xml which has relative layout and image view as child I want to retrieve those views to set their margins progrmatically here is my xml</p>

<pre><code>  &lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/Level1Layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="objectClick" 
            android:background="@drawable/hh_gmw_03"&gt;

    &lt;ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="593dp"
        android:layout_marginLeft="998dp" 
        android:onClick="objectClick" 
        android:contentDescription="Image1"
        android:tag="Image1"
        android:src="@drawable/hht3l01"/&gt;

    &lt;ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="39dp"
        android:layout_marginLeft="20dp" 
        android:onClick="objectClick" 
        android:contentDescription="Image1"
        android:tag="Image1"
        android:src="@drawable/hht3l02" /&gt;

    &lt;ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="153dp"
        android:layout_marginLeft="497dp" 
        android:onClick="objectClick" 
        android:contentDescription="Image1"
        android:tag="Image3"
        android:src="@drawable/hht3l03" /&gt;

    &lt;ImageView
        android:id="@+id/imageView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="524dp"
        android:layout_marginLeft="998dp" 
        android:onClick="objectClick" 
        android:contentDescription="Image1"
        android:tag="Image4"
        android:src="@drawable/hht3l04" /&gt;

    &lt;ImageView
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="183dp"
        android:layout_marginLeft="715dp" 
        android:onClick="objectClick" 
        android:contentDescription="Image1"
        android:tag="Image5"
        android:src="@drawable/hht3l05" /&gt;

    &lt;ImageView
        android:id="@+id/imageView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="413dp"
        android:layout_marginLeft="557dp" 
        android:onClick="objectClick" 
        android:contentDescription="Image1"
        android:tag="Image6"
        android:src="@drawable/hht3l06" /&gt;

    &lt;ImageView
        android:id="@+id/imageView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="53dp"
        android:layout_marginLeft="532dp" 
        android:onClick="objectClick" 
        android:contentDescription="Image1"
        android:tag="Image7"
        android:src="@drawable/hht3l07" /&gt;
&lt;/RelativeLayout&gt;
</code></pre>

<p>and here is my ExampleActivity </p>

<pre><code>public class ExampleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ImageView[] Objects = (ImageView[]) getViewArrays(R.layout.level1);
    Log.d("Check","Objects" + Objects.toString());
}



public View[] getViewArrays(int resid)
{
    ViewGroup layout = (ViewGroup) this.findViewById(resid);

    View[] views = new View[layout.getChildCount()];

    for (int i = 0; i &lt; layout.getChildCount(); i++) {
        views[i] = layout.getChildAt(i);
    }

    return views;
}

public int[] getViewIds(int resid)
{
    ViewGroup layout = (ViewGroup) this.findViewById(resid);

    int[] ids = new int[layout.getChildCount()];

    for (int i = 0; i &lt; layout.getChildCount(); i++) {
        ids[i] = layout.getChildAt(i).getId();
    }

    return ids;
}
</code></pre>

<p>}</p>

<p>It is giving me null exception error at this line 
View[] views = new View[layout.getChildCount()];  ...... Why my layout is not found ?</p>
