ClassCastException:android.widget.FrameLayout $ LayoutParams

时间:2016-03-01 07:16:48

标签: android eclipse android-studio

我将代码从Eclipse迁移到Android Studio。我收到以下错误

java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.view.WindowManager$LayoutParams
弹出窗口中的

。但是代码在Eclipse中完美运行,但在android studio中却没有。我无法找出问题所在。

我的代码是。

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 = "<html><body>"
                                        + "<p align=\"justify\">"
                                        + data
                                         + "</p> "
                                         + "</body></html>";

                                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);
                                    }
                                });
                            }

xml是

<?xml version="1.0" encoding="utf-8"?>
<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" >

<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" />

<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" />

</LinearLayout>

我的logcat是

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)

0 个答案:

没有答案