简体   繁体   中英

How to instantiate a class

I have a problem in my application , I can't instantiate a class

this is my 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)

And this is my method :

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

my Interface :

public interface ICreateFeature extends ICreate, IFeature {
 }

and my class

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

Your CreateStartEventFeature does not extend any class defined by you, so by calling super constructor

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

you try ro run parametrized constructor from Object class.

CreateStartEventFeature needs to implement the interface:

public class CreateStartEventFeature extends MyBaseClass implements ICreateFeature 
{...}

The question is a bit confusing since it doesn't show the whole problem, but I assume CreateStartEventFeature implements ICreateFeature, so try leaving out the explicit cast:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM