Wie Constructor mit Parametern benutzen (getConstructor)

Status
Nicht offen für weitere Antworten.

Empire Phoenix

Top Contributor
Nun ich habe einige Tutorials versucht nachzubauen, schitere daran aber aus irgenteinen Grund. Dies ist der Code, den ich hab:

Code:
String newobjectname = "de.empirephoenix.NewHorizons.Shared.GameObjects.Entities.Test.CDynamicEntityTest"
					Class<CEntity> classtospawn = (Class<CEntity>) ClassLoader.getSystemClassLoader().loadClass(newobjectname);
					Constructor<CEntity> constructor = classtospawn.getConstructor(new Class[]{Integer.TYPE});
					CEntity newobject = constructor.newInstance(new Object[]{new Integer(update.GetNetworkId())});

Das Problem ist, das ich diese Excpetion bekomme:

Code:
java.lang.NoSuchMethodException: de.empirephoenix.NewHorizons.Shared.GameObjects.Entities.Test.CDynamicEntityTest.<init>(int)
	at java.lang.Class.getConstructor0(Class.java:2706)
	at java.lang.Class.getConstructor(Class.java:1657)
	at de.empirephoenix.NewHorizons.Shared.GameObjects.Entities.CEntity.UpdateMessage(CEntity.java:32)
	at ObjectSyncroListener.messageReceived(ObjectSyncroListener.java:25)
	at com.captiveimagination.jgn.MessageServer.sendToListener(MessageServer.java:461)
	at com.captiveimagination.jgn.MessageServer.notifyIncoming(MessageServer.java:492)
	at com.captiveimagination.jgn.MessageServer.updateEvents(MessageServer.java:379)
	at com.captiveimagination.jgn.MessageServer.update(MessageServer.java:662)
	at com.captiveimagination.jgn.UpdatableRunnable.run(JGN.java:437)
	at java.lang.Thread.run(Thread.java:619)

Doch dieser constructor existiert in der Klasse:

Code:
public class CDynamicEntityTest extends CDynamicPhysicEntity {

	CDynamicEntityTest(int netid) {
		super(netid);
		Box box = new Box("lol",new Vector3f(0,0,0),1,1,1);
		box.setRandomColors();
		this.GetCNode().attachChild(box);
	}

}

//und die anderen beteiligen Klassen

	public CDynamicPhysicEntity(int netid) {
		super(netid);
		CNode = new Node();
		rootnode.attachChild(CNode);
	}

     	public CEntity(int netid){
		NetworkId = netid;
		clientsideobjects.put(netid, this);
	}
 
Code:
public class CDynamicEntityTest extends CDynamicPhysicEntity {

	[b]public[/b] CDynamicEntityTest(int netid) {
		super(netid);
		Box box = new Box("lol",new Vector3f(0,0,0),1,1,1);
		box.setRandomColors();
		this.GetCNode().attachChild(box);
	}

}
 
Doch dieser constructor existiert in der Klasse:
Aber sichtbar ist er nicht. Entweder du machst ihn public, oder du nimmst getDeclaredConstructor + setAccessible(true), aber das funktioniert nur wenn der Security Manager es nicht verbietet.
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben