我正在运行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。

最佳答案

您的模型包含一个ArrayList实例,并且您试图将其强制转换为SelectionGroupnew Model(new SelectionGroup())应该修复它。

10-05 19:13