我正在运行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();
}
错误:
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。
答案 0 :(得分:1)
您的模型包含ArrayList
个实例,并且您正尝试将其强制转换为SelectionGroup
。 new Model(new SelectionGroup())
应该修复它。