0

我的应用程序有问题,我无法实例化一个类

这是我的java.lang.ClassCastException

eclipse.emf.editeurgraphique.risque.features.StartEventFeature$CreateStartEventFeature cannot be cast to org.eclipse.graphiti.features.ICreateFeature 
at eclipse.emf.editeurgraphique.risque.features.StartEventFeature.getCreateFeature(StartEventFeature.java:43)

这是我的方法:

 public ICreateFeature getCreateFeature(IFeatureProvider fp) {
    return (ICreateFeature) new CreateStartEventFeature(fp);
}

我的界面:

public interface ICreateFeature extends ICreate, IFeature {
 }

和我的班级

 public CreateStartEventFeature(IFeatureProvider fp) {
        super(fp, "Start Event", "Indicates the start of a process or    choreography");
    }
4

3 回答 3

0

这个问题有点令人困惑,因为它没有显示整个问题,但我假设 CreateStartEventFeature 实现了 ICreateFeature,因此请尝试省略显式转换:

public ICreateFeature getCreateFeature(IFeatureProvider fp) {
    return new CreateStartEventFeature(fp);
}
于 2014-05-24T21:51:54.323 回答
0

您的 CreateStartEventFeature 不会扩展您定义的任何类,因此通过调用超级构造函数

super(fp, "Start Event", "Indicates the start of a process or    choreography");

您尝试从 Object 类运​​行参数化构造函数。

于 2014-05-24T21:37:52.553 回答
0

CreateStartEventFeature 需要实现接口:

public class CreateStartEventFeature extends MyBaseClass implements ICreateFeature 
{...}
于 2014-05-24T21:40:33.323 回答