java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wid
2014-09-10 12:02
691 查看
今天在代码中使用一个RelativeLayout.getLayoutParams()函数时,赋值给RelativeLayout.LayoutParams时,出现如下的报错信息:
好吧,往往就忽略了一个问题,这个LayoutParams是之类从父类获取到了,明白这一点,就知道怎么回事了,而我的父类是一个LinearLayout,所以:
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams这段话提示我们不能将Linear$LayoutParams强制转换成RelativeLayout$LayoutParams可是自己看了下,当前view确实是RelativLayout的之类,调用getLayoutParams应该没有问题呀~
好吧,往往就忽略了一个问题,这个LayoutParams是之类从父类获取到了,明白这一点,就知道怎么回事了,而我的父类是一个LinearLayout,所以:
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) this.getLayoutParams();这样就没问题了
相关文章推荐
- java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wid
- java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wid
- java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wid
- :java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wi
- java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.wid
- java.lang.ClassCastException: 。。。$LayoutParams cannot be cast to android.widget.LinearLayout$Layout
- java.lang.ClassCastException:android.widget.LinearLayout$LayoutParams cannot be cast to android.widg
- java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wi
- java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w
- java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widg
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.L(转)
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutPara
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.R
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.
- java.lang.ClassCastException: android.app.ActionBar$LayoutParams cannot be cast to android.widget.Ab
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w