ClassCastException: android.widget.FrameLayout$LayoutParams
<p>I migrated the code from Eclipse to Android Studio. And I am getting this below error</p>

<pre><code>java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.view.WindowManager$LayoutParams
</code></pre>

<p>in the popup window. But the code works perfectly in Eclipse but not in android studio. And I am unable to find out what is the problem.</p>

<p>And my code is.</p>

<pre><code>private void popup_otp() {
                                // TODO Auto-generated method stub
                                View popupView = LoginActivity.this.getLayoutInflater()
                                        .inflate(R.layout.pop_up_otp, null);

                                DisplayMetrics metrics = new DisplayMetrics();
                                getWindowManager().getDefaultDisplay().getMetrics(metrics);

                                int height = metrics.heightPixels;
                                int width = metrics.widthPixels;

                                /*
                                 * int h = height; double a= width /4;
                                 */
                                int wwidth = width / 6;
                                int w = width - wwidth;

                                final PopupWindow popupWindow = new PopupWindow(popupView, w,
                                        LayoutParams.WRAP_CONTENT);
                                popupWindow.setFocusable(true);

                                popupWindow.setBackgroundDrawable(new BitmapDrawable(
                                        getResources(), ""));

                                //popupWindow.showAtLocation(v, Gravity.CENTER, 0, 0);

                                // If you need the PopupWindow to dismiss when when touched
                                // outside
                                // popupWindow.setBackgroundDrawable(new ColorDrawable());
                                ColorDrawable dw = new ColorDrawable(0xb0000000);
                                popupWindow.setBackgroundDrawable(dw);
                                int location[] = new int[2];

                                // Get the View's(the one that was clicked in the Fragment)
                                // location
                                popupView.getLocationOnScreen(location);

                                // Using location, the PopupWindow will be displayed right under
                                // anchorView
                                popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);

                                View container = (View) popupWindow.getContentView().getParent();
                                WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
                                WindowManager.LayoutParams p = (WindowManager.LayoutParams) container
                                        .getLayoutParams();
                                p.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
                                p.dimAmount = 0.8f;
                                wm.updateViewLayout(container, p);

                                TextView ok_submit_txtView=(TextView)popupView.findViewById(R.id.ok_submit_txtView);
                                WebView webview=(WebView)popupView.findViewById(R.id.web_view_item);
                                String data="Dear user, you have not completed the OTP verification yet.You will be now redirected to the OTP screen and your OTP will be resent to you.";
                                String text = "&lt;html&gt;&lt;body&gt;"
                                        + "&lt;p align=\"justify\"&gt;"
                                        + data
                                         + "&lt;/p&gt; "
                                         + "&lt;/body&gt;&lt;/html&gt;";

                                webview.loadData(text, "text/html", "utf-8");
                                ok_submit_txtView.setOnClickListener(new OnClickListener() {

                                    @Override
                                    public void onClick(View v) {
                                        // TODO Auto-generated method stub

                                        popupWindow.dismiss();

                                        Intent intent = new Intent(LoginActivity.this, OTPActivity.class);
                                        intent.putExtra("OTP", OTP);
                                        intent.putExtra("checking", 22);
                                        startActivity(intent);
                                        System.out.println("otp" + OTP + responce_message);
                                    }
                                });
                            }
</code></pre>

<p>And the xml is</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:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical" &gt;

&lt;WebView
    android:id="@+id/web_view_item"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_margin="10dp"
    android:textColor="#000000" /&gt;

&lt;TextView
    android:id="@+id/ok_submit_txtView"
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_margin="10dp"
    android:gravity="center"
    android:text="OK"
    android:textColor="@color/dark_red"
    android:textSize="16sp" /&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>And my logcat is</p>

<pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                                                             Process: com.truetech.lola, PID: 7725
                                                             java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.view.WindowManager$LayoutParams
                                                                 at com.truetech.lola.login.LoginActivity$CHECK_OTP$1.popup_otp(LoginActivity.java:569)
                                                                 at com.truetech.lola.login.LoginActivity$CHECK_OTP$1.run(LoginActivity.java:518)
                                                                 at android.os.Handler.handleCallback(Handler.java:746)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                 at android.os.Looper.loop(Looper.java:148)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:5443)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
</code></pre>