zoukankan      html  css  js  c++  java
  • 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));

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

  • 相关阅读:
    HTTP协议
    idea新建工程项目结构
    idea使用的JDK版本1.9换成1.8后相关的更改设置
    Servlet
    Tomcat三种项目部署方式
    Tomcat环境变量配置命令行报错:The JRE_HOME environment variable is not defined correctl This environment variable is needed to run this program
    JDBC面试题
    XML基础入门
    数据库连接池——Druid
    $.ajax 分页
  • 原文地址:https://www.cnblogs.com/dongweiq/p/3921879.html
Copyright © 2011-2022 走看看