This site requires JavaScript, please enable it in your browser!
Greenfoot back
Upupzealot
Upupzealot wrote ...

2014/1/27

Need help with Constructor involk in jar file

Upupzealot Upupzealot

2014/1/27

#
Constructor constructor = this.getClass().getClassLoader().loadClass(ClassName).getDeclaredConstructor(parameterTypes);// Class.forName(ClassName).getDeclaredConstructor(parameterTypes);
ScrollObject SO = (ScrollObject)constructor.newInstance(parameters);
these codes works well in Greenfoot, but in a jar file, it will throw "java.lang.reflect.InvocationTargetException" I want to know how to solve this problem. My aim is to get new instance by a String of the class's name.
Upupzealot Upupzealot

2014/1/27

#
I tried publish it to the greenfoot gallery here, and the code didn't work also.
Upupzealot Upupzealot

2014/1/27

#
I find the reason for this question! It happens when the Construtor wanted to load a GreenfootImage which is not in the "images" directory, such as "images/brush/rock.png"
You need to login to post a reply.