Instantiating from constructor with non primitive

Hello,
I’m working on some network code, and i want to instantiate an object. I’m sending the EntityType over the network which goes fine. I’ve got a class called EntityList which holds all the classes and the types (hashmaps). That works good as well. Now the last thing i’m trying to do is instantiate the object with a constructor.

Entity entity = EntityList.getEntity(((EntityCreation) object).entityType).getConstructor(EntityCreation.class).newInstance((EntityCreation)object);
entityManager.createEntity(entity);

Sadly enough this doesnt work. to clarify some more, i’m sending an entityType of 1 here. Which returns TestEntity.class from the entityList.
TestEntity extends MovingUnit extends SelectableUnit extends Unit extends Entity.
This is the constructor i’m trying to acces:

public TestEntity(EntityCreation entityCreation) {
//CODE here
}

Now it is throwing a “java.lang.reflect.InvocationTargetException”. With the .getCause() function i’m trying to debug it, and it is returning a NullPointerException. I take it that it can’t find the constructor?
Any help would be greatly appreciated!

http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/InvocationTargetException.html

This exception is thrown when the target method (constructor) throws an exceptions. It wraps it, calling getCause() returns the wrapped exception.

Your exception is being thrown from within your constructor, maybe it is referencing it’s first argument (which you may have passed null to.)

I can’t help you any further without seeing the constructor.

Thanks. Silly me for not reading trough the api :emo:. Turns out i had made another change which threw an error in the constructor from a totally different class.
Thanks a bunch!