I am getting ClassCastException in onCreat() mehtod?
<p>I want to change view height and width, (might be button view, image view, linearlayout, framelayout or any kind of view). I uses a method traverseRootViewAndSetLayoutParam(View,
            double , double), to change do this. Its working if i commented these lines.</p>

<pre><code>    if (view.getClass().equals(LinearLayout.class)) {
         LinearLayout.LayoutParams layoutParams = new
         LinearLayout.LayoutParams(
         (int) (((double) widthRatio) * (view.getWidth())),
         (int) (((double) heightRatio) * (view.getHeight())));
         view.setLayoutParams(layoutParams);
    } else if (view.getClass().equals(FrameLayout.class)) {
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                (int) (((double) widthRatio) * (view.getWidth())),
                (int) (((double) heightRatio) * (view.getHeight())));
        view.setLayoutParams(layoutParams);
    }
</code></pre>

<p>, but if i run all the code than I am getting ClassCastException in onCreate() method, </p>

<p>I debug the code, the method traverseRootViewAndSetLayoutParam(View, double , double) is not giving the exception, but after control passes over the onCreate(), it gives the ClassCastException. I check it the control comes on line , System.outprintln(>> oncreate end >>). at this time i am not getting any error, but crossing the oncreate method exception occur.  </p>

<p>the lines of code i am calling in onCreate method,</p>

<pre><code>@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            ...
            ...
            ...
    try {
        traverseRootViewAndSetLayoutParam(rootLinearLayout, widthRatio,
                heightRatio);
    } catch (Exception e) {
        e.printStackTrace();
    }
System.out.println("&gt;&gt;&gt; oncreate end &gt;&gt;&gt; ");
   }
</code></pre>

<p>traverseRootViewAndSetLayoutParam() method,</p>

<pre><code>public void traverseRootViewAndSetLayoutParam(View view,
        double heightRatio, double widthRatio) {

    System.out.println("&gt;&gt;&gt; iCount &gt;&gt;&gt; " + iCount++);

    if (view.getClass().equals(LinearLayout.class)) {
         LinearLayout.LayoutParams layoutParams = new
         LinearLayout.LayoutParams(
         (int) (((double) widthRatio) * (view.getWidth())),
         (int) (((double) heightRatio) * (view.getHeight())));
         view.setLayoutParams(layoutParams);
    } else if (view.getClass().equals(FrameLayout.class)) {
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                (int) (((double) widthRatio) * (view.getWidth())),
                (int) (((double) heightRatio) * (view.getHeight())));
        view.setLayoutParams(layoutParams);
    }
    // else {
    // ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
    // (int) (((double) widthRatio) * (view.getWidth())),
    // (int) (((double) heightRatio) * (view.getHeight())));
    // view.setLayoutParams(layoutParams);
    // }

    if (view instanceof LinearLayout || view instanceof FrameLayout) {
        if (view instanceof LinearLayout) {
            System.out.println("&gt;&gt;&gt; LinearLayout Class &gt;&gt;&gt; "
                    + view.getClass());
            int childcount = ((LinearLayout) view).getChildCount();
            for (int i = 0; i &lt; childcount; i++) {
                View childView = ((LinearLayout) view).getChildAt(i);
                traverseRootViewAndSetLayoutParam(childView, heightRatio,
                        widthRatio);
            }
        } else if (view instanceof FrameLayout) {
            System.out.println("&gt;&gt;&gt; FrameLayout Class &gt;&gt;&gt; "
                    + view.getClass());
            int childcount = ((FrameLayout) view).getChildCount();
            for (int i = 0; i &lt; childcount; i++) {
                View childView = ((FrameLayout) view).getChildAt(i);
                traverseRootViewAndSetLayoutParam(childView, heightRatio,
                        widthRatio);
            }
        }
    }
}
</code></pre>

<p>error log,</p>

<pre><code>12-16 00:30:12.791: W/dalvikvm(277): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-16 00:30:12.952: E/AndroidRuntime(277): FATAL EXCEPTION: main
12-16 00:30:12.952: E/AndroidRuntime(277): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:355)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.View.measure(View.java:8171)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:696)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:306)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.View.measure(View.java:8171)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.View.measure(View.java:8171)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.View.measure(View.java:8171)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.View.measure(View.java:8171)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.View.measure(View.java:8171)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.os.Looper.loop(Looper.java:123)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-16 00:30:12.952: E/AndroidRuntime(277):  at java.lang.reflect.Method.invokeNative(Native Method)
12-16 00:30:12.952: E/AndroidRuntime(277):  at java.lang.reflect.Method.invoke(Method.java:521)
12-16 00:30:12.952: E/AndroidRuntime(277):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-16 00:30:12.952: E/AndroidRuntime(277):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-16 00:30:12.952: E/AndroidRuntime(277):  at dalvik.system.NativeStart.main(Native Method)
12-16 00:30:42.751: I/Process(277): Sending signal. PID: 277 SIG: 9
</code></pre>
