Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Instantiating from constructor with non primitive  (Read 295 times)
0 Members and 1 Guest are viewing this topic.
Offline elamre

JGO Coder


Medals: 17
Projects: 1


hitar!


« Posted 2013-09-16 18:55:48 »

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.
1  
2  
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:
1  
2  
3  
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!

My projects:
Tower Defence!]http://www.java-gaming.org/topics/iconified/25690/view.html]Tower Defence! [lll.......] 30%!
Lightsnakerider! [llllll....] 60%!
Offline Jeremy
« Reply #1 - Posted 2013-09-16 19:07:56 »

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.

JevaEngine, Latest Playthrough (This demo is networked with a centralized server model)

http://www.youtube.com/watch?v=rWA8bajpVXg
Offline elamre

JGO Coder


Medals: 17
Projects: 1


hitar!


« Reply #2 - Posted 2013-09-16 19:14:24 »

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!

My projects:
Tower Defence!]http://www.java-gaming.org/topics/iconified/25690/view.html]Tower Defence! [lll.......] 30%!
Lightsnakerider! [llllll....] 60%!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (20 views)
2014-09-21 02:42:18

BurntPizza (14 views)
2014-09-21 01:30:30

moogie (14 views)
2014-09-21 00:26:15

UprightPath (25 views)
2014-09-20 20:14:06

BurntPizza (27 views)
2014-09-19 03:14:18

Dwinin (40 views)
2014-09-12 09:08:26

Norakomi (73 views)
2014-09-10 13:57:51

TehJavaDev (96 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!