开发者

java.lang.ClassCastException: java.util.ArrayList

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:开发者_如何学JAVA54)
    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.


Your model consists of an ArrayList instance and you are trying to cast it to SelectionGroup. new Model(new SelectionGroup()) should fix it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜