概述
09-09 10:19:59.979: E/AndroidRuntime(2767): FATAL EXCEPTION: main
09-09 10:19:59.979: E/AndroidRuntime(2767): java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.widget.LinearLayout.measureVertical(LinearLayout.java:634)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.view.View.measure(View.java:12758)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.view.View.measure(View.java:12758)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.view.View.measure(View.java:12758)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.view.View.measure(View.java:12758)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2445)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.os.Handler.dispatchMessage(Handler.java:99)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.os.Looper.loop(Looper.java:137)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at android.app.ActivityThread.main(ActivityThread.java:4424)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at java.lang.reflect.Method.invokeNative(Native Method)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at java.lang.reflect.Method.invoke(Method.java:511)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
09-09 10:19:59.979: E/AndroidRuntime(2767):
at dalvik.system.NativeStart.main(Native Method)
报错原因:
ImageView image =(ImageView) findViewById(R.id.imageView1);
image.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
解决方法:
ImageView image =(ImageView) findViewById(R.id.imageView1);
image.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
小结:
遇到问题时,解决思路有哪些,强化下,第一理清问题环境和背景,如查看如上错误提示,马上就可以定位问题,快速解决。第二、三、四,
其实它不算是问题。为了强化这种思路,在此记录下。
最后
以上就是淡定毛衣为你收集整理的java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.L的全部内容,希望文章能够帮你解决java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.L所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复