• java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.L(转)


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

    小结:
    遇到问题时,解决思路有哪些,强化下,第一理清问题环境和背景,如查看如上错误提示,马上就可以定位问题,快速解决。第二、三、四,
    其实它不算是问题。为了强化这种思路,在此记录下。

  • 相关阅读:
    30分钟带你了解Docker
    30分钟了解Springboot整合Shiro
    vuejs 和 element 搭建的一个后台管理界面
    MySQL缓存参数优化(转)
    MVC+EF(CODEFIRST)+EASYUI医药MIS系统
    博客园开通打赏功能以及HTTPS打赏失效的探究 -玩转打赏功能
    SpringMVC集成rabbitmq:优化秒杀下单环节
    国内最火5款Java微服务开源项目
    SpringCloud系列——SSO 单点登录
    玩转spring boot
  • 原文地址:https://www.cnblogs.com/dongweiq/p/3921879.html
Copyright © 2020-2023  润新知