title: ClassCastException ViewGroup$LayoutParams cannot be cast to ViewPager$LayoutParams
body: <p>My initial code line is inside the overridden method <code>onGlobalLayout()</code>:</p>
  
  <pre><code>img.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 100));
  </code></pre>
  
  <p>ClassCastException occuring in the overridden method <code>onGlobalLayout()</code>-</p>
  
  <p><strong>Error Log:</strong></p>
  
  <pre><code>09-02 14:25:35.326: E/AndroidRuntime(5187): java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.support.v4.view.ViewPager$LayoutParams
  09-02 14:25:35.326: E/AndroidRuntime(5187):     at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1319)
  09-02 14:25:35.326: E/AndroidRuntime(5187):     at android.view.View.measure(View.java:15181)
  09-02 14:25:35.326: E/AndroidRuntime(5187):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
  09-02 14:25:35.326: E/AndroidRuntime(5187):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
  09-02 14:25:35.326: E/AndroidRuntime(5187):     at android.view.View.measure(View.java:15181)
  09-02 14:25:35.326: E/AndroidRuntime(5187):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
  09-02 14:25:35.326: E/AndroidRuntime(5187):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
  </code></pre>
  
  <p>And when I do the following in order to resolve the above error as indicated in other SO posts:</p>
  
  <pre><code>img.setLayoutParams(new ViewPager.LayoutParams(ViewPager.LayoutParams.MATCH_PARENT, 100));
  </code></pre>
  
  <p>Then, I get the compile time error: </p>
  
  <pre><code>The constructor ViewPager.LayoutParams(int, int) is undefined
  </code></pre>
  
  <p>ViewPager in xml is defined like:</p>
  
  <pre><code>&lt;android.support.v4.view.ViewPager
   android:id="@+id/HView"
   android:layout_width="560dp"
   android:layout_height="255dp"
   android:layout_centerHorizontal="true"
   android:layout_marginLeft="160sp"
   android:layout_marginTop="110sp"
   android:layout_marginBottom="80sp"&gt;
   &lt;/android.support.v4.view.ViewPager&gt;
  </code></pre>