java.lang.ClassCastException:java.util.ArrayList

发布于 2024-11-17 03:40:28 字数 1684 浏览 0 评论 0原文

我正在运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满天都是小星星 2024-11-24 03:40:28

您的模型由 ArrayList 实例组成,并且您尝试将其转换为 SelectionGroupnew Model(new SelectionGroup()) 应该修复它。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文