SWT中调用SetLayout 遇到ClassCastException: GridData cannot be cast to RowData 问题调查
来源:互联网 发布:广东11选5当前遗漏数据 编辑:程序博客网 时间:2024/06/06 17:09
问题
在华能客户端开发过程中,使用SWT 开发的GUI, 在修改代码将其中的一个SashForm 改为Composite 之后,运行程序会遇到如下的Exception.
- java.lang.ClassCastException: org.eclipse.swt.layout.GridData cannot be cast to org.eclipse.swt.layout.RowData
- at org.eclipse.swt.layout.RowLayout.layoutVertical(RowLayout.java:367)
- at org.eclipse.swt.layout.RowLayout.computeSize(RowLayout.java:206)
- at org.eclipse.swt.widgets.Composite.computeSize(Composite.java:231)
- at org.eclipse.swt.layout.FillData.computeSize(FillData.java:26)
- at org.eclipse.swt.layout.FillLayout.computeChildSize(FillLayout.java:151)
查找原因
从最后改动的代码中没有找到可能出错的地方,于是Google搜索如下语句: java.lang.ClassCastException: org.eclipse.swt.layout.GridData cannot be cast toorg.eclipse.swt.layout.RowData
看到这个网页:http://www.eclipse.org/forums/index.php/mv/msg/36739/119448/
其中有如下的讨论:
you can't be surethat the layout of the parent composite is a
GridLayout. And using a GridData together with a nonGridLayout (eg.
FillLayout as in your case) will always fail at runtime(same goes for SWT).
结合这个实例,猜测可能与GridData 有关,搜索代码看到的确有SetLayoutData(new GridData(…))的调用,具体的Widget 关系如下。括号内为Layout, 箭头方向为父控件->子控件。
Container(GridLayout)->SashForm->SashForm->TabFolder(FillLayout)->SashForm->Table
代码中有上面的Table 调用setLayoutData(new GridData(GridData.FILL_BOTH)) . 尝试取消这个调用,问题就不重现了。
解决方法
将前面的TabFolder 的Layout 由FillLayout 改为GridLayout. 问题解决,不再重现。
- SWT中调用SetLayout 遇到ClassCastException: GridData cannot be cast to RowData 问题调查
- ClassCastException: $Proxy0 cannot be cast to ...
- ClassCastException:ColorDrawable cannot be cast to RoundRectDrawableWithShadow
- ClassCastException:SpannableString cannot be cast to String
- struts2的<s:iterator>标签 遇到的问题:java.lang.ClassCastException:cannot be cast to java.lang.String
- 打混淆包的时候 遇到一个 java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to ..问题
- 在使用spring+springMVC+hibernate遇到java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to
- Android 从 View 中获取 Activity 时遇到 TintContextWrapper cannot be cast to 的问题
- java.lang.ClassCastException: android.app.Application cannot be cast to serialport_api.sample.App问题
- java.lang.ClassCastException: android.app.Application cannot be cast to serialport_api.sample.App问题
- java.lang.ClassCastException: android.app.Application cannot be cast to serialport_api.sample.App问题
- java.lang.ClassCastException: android.app.Application cannot be cast to serialport_api.sample.App问题
- java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to 问题
- 问题 java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to
- struts2 下载问题java.lang.ClassCastException: java.io.ByteArrayInputStream cannot be cast to
- 在SSH整合过程中ClassCastException:xxx_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy
- java.lang.ClassCastException: $Proxy cannot be cast to
- java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to ]
- struts2标签详解
- Android - Layout 也是 View
- centos ve12.05启动vm失败
- 解决在调用第三方dll时因为runtime library不一致导致调用失败的方法
- C++的函数重载
- SWT中调用SetLayout 遇到ClassCastException: GridData cannot be cast to RowData 问题调查
- struts标签小结
- jQuery对象与dom对象的转换
- 嵌套定义
- SQL 优化之该走索引却不走索引的分析(二)
- 认识静态链接库和linux下的创建
- HDU2964Prime Bases简单数学题
- 80后海归硕士晒月薪70000的磨难 没有熬不过来的苦
- 子进程复制了父进程的什么