Hello friends. I have a function in which one of the parameters is Class<? extends Image> klass in which a class that extends image can be passed in to, the issue is, I am trying to call the constructor of that passed in klass, and create a new object of it. I am getting this error when I try to run it.
java.lang.NoSuchMethodException: world.ntdi.planium.manger.image.images.Longer.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3585) ~[na:na]
at java.base/java.lang.Class.getConstructor(Class.java:2271) ~[na:na]
at world.ntdi.planium.controller.PresetController.checkImageLocation(PresetController.java:43) ~[classes/:na]
at world.ntdi.planium.controller.PresetController.createLong(PresetController.java:32) ~[classes/:na]```
Heres my code:
```java
private ImageLocation checkImageLocation(String text, Integer fontSize, Integer x, Integer y, String bufferedIO, Class<? extends Image> klass) throws IOException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
String serialized = ImageSerialization.serializeName(fontSize, x, y, text, ImageIO.read(new File(bufferedIO)));
if (cache.get(serialized) != null) {
return new ImageLocation("localhost:8080/cache/" + cache.get(serialized).getFile().getName());
}
Constructor<? extends Image> constructor = klass.getConstructor();
Image image = constructor.newInstance(text, fontSize, x, y);
cache.put(image.getSerializeName(), image);
return new ImageLocation("localhost:8080/cache/" + image.getFile().getName());
}``` Let me know if there is any code I can send to help!