java.lang.ClassCastException:java.util.ArrayList
我正在运行 Junit 测试,出现错误:
GroupOptionInputPanelTest.java:
public void setUp() {
groupOptionInputPanel = new GroupOptionInputPanel(TEST_ID, new Model(new ArrayList()), null);
}
GroupOptionInputPanel.java:
public GroupOptionInputPanel(String id, IModel model, final Form parentForm) {
this(id, model, parentForm, false);
}
...
ListView options = new GroupElementListView("options", getSelectionGroup().getSelectionOptions(), getInitTabIndex()) {
..
public abstract class AbstractOptionPanel extends Panel {
public SelectionGroup getSelectionGroup() {
return (SelectionGroup) getModel().getObject();
}
error:
java.lang.ClassCastException: java.util.ArrayList
at com.bgc.ordering.wizard.front.groupoptions.AbstractOptionPanel.getSelectionGroup(AbstractOptionPanel.java:33)
at com.bgc.ordering.wizard.front.groupoptions.GroupOptionInputPanel.<init>(GroupOptionInputPanel.java:54)
at com.bgc.ordering.wizard.front.groupoptions.GroupOptionInputPanel.<init>(GroupOptionInputPanel.java:47)
如何解决此错误?
public GroupOptionInputPanel(String id, IModel model, final Form parentForm, final boolean canDisplayExclamationMark) {
super(id, model);
this.setOutputMarkupId(true);
ListView options = new GroupElementListView("options", getSelectionGroup().getSelectionOptions(), getInitTabIndex()) {
public Model(Serializable object)
{
setObject(object);
}
模型是 Wicket API。
I am running Junit test, getting error:
GroupOptionInputPanelTest.java:
public void setUp() {
groupOptionInputPanel = new GroupOptionInputPanel(TEST_ID, new Model(new ArrayList()), null);
}
GroupOptionInputPanel.java:
public GroupOptionInputPanel(String id, IModel model, final Form parentForm) {
this(id, model, parentForm, false);
}
...
ListView options = new GroupElementListView("options", getSelectionGroup().getSelectionOptions(), getInitTabIndex()) {
..
public abstract class AbstractOptionPanel extends Panel {
public SelectionGroup getSelectionGroup() {
return (SelectionGroup) getModel().getObject();
}
error:
java.lang.ClassCastException: java.util.ArrayList
at com.bgc.ordering.wizard.front.groupoptions.AbstractOptionPanel.getSelectionGroup(AbstractOptionPanel.java:33)
at com.bgc.ordering.wizard.front.groupoptions.GroupOptionInputPanel.<init>(GroupOptionInputPanel.java:54)
at com.bgc.ordering.wizard.front.groupoptions.GroupOptionInputPanel.<init>(GroupOptionInputPanel.java:47)
How can I solve this error?
public GroupOptionInputPanel(String id, IModel model, final Form parentForm, final boolean canDisplayExclamationMark) {
super(id, model);
this.setOutputMarkupId(true);
ListView options = new GroupElementListView("options", getSelectionGroup().getSelectionOptions(), getInitTabIndex()) {
public Model(Serializable object)
{
setObject(object);
}
Model is Wicket API.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的模型由
ArrayList
实例组成,并且您尝试将其转换为SelectionGroup
。new Model(new SelectionGroup())
应该修复它。Your model consists of an
ArrayList
instance and you are trying to cast it toSelectionGroup
.new Model(new SelectionGroup())
should fix it.