Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.view.WindowManager$LayoutParams #52

Closed
Xiaa520 opened this issue Jan 17, 2018 · 18 comments

Comments

@Xiaa520
Copy link

Xiaa520 commented Jan 17, 2018

该问题是怎么引起的?

at android.widget.PopupWindow$1.onScrollChanged(PopupWindow.java:149)
at android.view.ViewTreeObserver.dispatchOnScrollChanged(ViewTreeObserver.java:1016)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2464)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2396)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2026)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1104)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5962)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:794)
at android.view.Choreographer.doCallbacks(Choreographer.java:607)
at android.view.Choreographer.doFrame(Choreographer.java:577)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:780)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5296)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)

重现步骤

报错信息/系统版本

建议或优化点

@ParfoisMeng
Copy link
Contributor

java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.view.WindowManager$LayoutParams
at android.widget.PopupWindow.getDecorViewLayoutParams(PopupWindow.java:2282)
at android.widget.PopupWindow.alignToAnchor(PopupWindow.java:2427)
at android.widget.PopupWindow.lambda$-android_widget_PopupWindow_10383(PopupWindow.java:262)
at android.widget.-$Lambda$ISuHLqeK-K4pmesAfzlFglc3xF4$1.$m$0(Unknown Source:17)
at android.widget.-$Lambda$ISuHLqeK-K4pmesAfzlFglc3xF4$1.onLayoutChange(Unknown Source:0)
at android.view.View.layout(View.java:19799)
at android.view.ViewGroup.layout(ViewGroup.java:6144)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2653)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2356)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1512)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7218)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:981)
at android.view.Choreographer.doCallbacks(Choreographer.java:790)
at android.view.Choreographer.doFrame(Choreographer.java:721)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:967)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7415)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

相同的错误吧

@razerdp
Copy link
Owner

razerdp commented Jan 17, 2018

@XZWQuickness
@ParfoisMeng

请问是什么版本,以及复现步骤

@Xiaa520
Copy link
Author

Xiaa520 commented Jan 18, 2018

小米2a 版本5.1.1 多次显示showPopupWindow 销毁dismiss 就会出现

@razerdp
Copy link
Owner

razerdp commented Jan 19, 2018

好的,我尽快解决

@ParfoisMeng
Copy link
Contributor

@razerdp 我这边是,dismiss的时候,对activity里的recycleview的adapter做刷新notifyDataSetChanged,崩溃。如果让notifyDataSetChanged延迟几秒就没事。感觉应该是pop未完全销毁前,操作activity内布局刷新导致

@razerdp
Copy link
Owner

razerdp commented Jan 19, 2018

其实是跟一个滑动有关大概,因为popup内部有监听scroll事件(用于将popup与anchorView对齐的)

而因为popup给add到windowmanager时用的是WindowManager.LayoutParams,而我这边因为hack掉windowmanager同时在addView时,给内部的decorView再加一层,导致了一个问题,就是两边的layoutParams可能不一致。

详情定位到:

popupwindow-> alignToAnchor()方法源码点我

外部scroll时回调到scrolllistener,其内部有获取layoutParams方法

final WindowManager.LayoutParams p = getDecorViewLayoutParams();

这里因为decorView被我add到了hackpopupdecorView,因此被我转为了viewGroup的LayoutParams,这里报错可能是因为向下转型的问题,目前解决方案我来想想哈。。。

hackwindowmanager

@ParfoisMeng
Copy link
Contributor

@razerdp 1.8.2没问题,1.9.2崩溃,中间版本未测试。

@razerdp
Copy link
Owner

razerdp commented Jan 19, 2018

嗯呐,1.9.1开始用windowmanager代理这个方法,当时自己测试也没遇到这个问题,现在遇到的话我在下个版本解决哈~

顺便问下- -崩溃频率高不高

@liaolintao
Copy link

我也遇到这个问题了, 挺容易触发的.

信息

BasePopup:1.9.2;
手机魅蓝note5, android6.0,

重新步骤

1.showPopupWindow(view);
2. 点击空白, pop消失

反复几次就crash了.

@Mr-PolarBear
Copy link

我也遇到了哈
当同个页面 有一个textview setSelected(true)(由于文字太长 文字横向滚动 跑马灯效果)
这时候点击显示popupwindow 会报这个错误

还有个问题顺便反馈下 - -

新版本 1.9.2 input类型的popupwindow 不会自动随输入法 而弹到上方 如果屏幕太小 输入法会遮住popupwindow

@ParfoisMeng
Copy link
Contributor

@razerdp 我那样的使用方式操作流程,崩溃是必现的。他们的问题不清楚是否必现,但概率应该都很高

@razerdp
Copy link
Owner

razerdp commented Jan 23, 2018

@Mr-PolarBear

那个输入法的问题是跟全屏有关的,因为popupHelper默认全屏(N以上可以把popup覆盖到状态栏)BasePopupHelper#50HackWindowmanager#180

所以布局无法顶上去,又因为这个跟activity全屏一样,当设置为全屏flag LayoutParams.FLAG_LAYOUT_IN_SCREEN时,输入法就已经是由window来控制了,所以布局无法resize,这个问题暂时无解

目前来说,可以禁用全屏来折中:

popup.setPopupWindowFullScreen(false);

@razerdp
Copy link
Owner

razerdp commented Jan 23, 2018

@XZWQuickness
@ParfoisMeng
@liaolintao
@bryant1410

感谢你们的反馈,新版本已经修复强转问题了,请更新到1.9.3 (ps,我是在模拟器测试的,没有测试到4.1~4.2)

razerdp added a commit that referenced this issue Jan 23, 2018
@liaolintao
Copy link

已解决, 谢谢!

验证步骤

1.在外侧滚动RecyclerView
2.在RecyclerView还未停下来的时候, showPopupWindow(view)

@razerdp
Copy link
Owner

razerdp commented Jan 24, 2018

3Q,如果还有什么问题欢迎提交issue哦

@yang0000meng
Copy link

yang0000meng commented Jan 28, 2018

我也遇到了哈 ,调试了一下午,模拟器没问题 ,小米手机 必现。唉。。来这看看 结果是库引起的。
更新后 发现一个问题
选中RecyclerView 某一行后 原来在底部,一下 就全屏了。

@razerdp
Copy link
Owner

razerdp commented Jan 28, 2018

@yang0000meng 你好,可以开个新的issue具体描述下吗。。。。。还有重现方案-

recyclerview在demo中DismissControlPopupFrag也有哦。

@hezhipengzipp
Copy link

吓得我赶紧升级1.9.3

razerdp added a commit that referenced this issue Dec 7, 2018
razerdp added a commit that referenced this issue Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants