java.lang.NoClassDefFoundError

Hello,

I am trying to load an image from a url and crop it. I created a method and uploaded it to the hosted services in the business logic section. My java code looks similar to this.

public void uploadProfilePhoto(int x, int y, int w, int h, String filePath) {
    try {
        BufferedImage originanlImg = ImageIO.read(new URL(filePath));
        
        BufferedImage croppedImg = originanlImg.getSubimage(x, y, w, h);
    } catch (IOException e) {
        logger.debug(e.getMessage());
    }
}

However, it is crashing on the ImageIO.read line. I am getting this error when I test it in the console:

{
“code”: 0,
“message”: “java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIOServiceException”
}

Any advice?

Hi Phil,

It is either the call to ImageIO.read creates a thread (which is not allowed yet in custom code) or one of the dependent classes is missing in the jar you deployed.

Regards,
Mark

Try changing the catch clause to catch Throwable and see what it catches.

Regards,
Mark

I have the same error Could not initialize class javax.imageio.ImageIO
What should i add else to project?

My call to ImageIO.read was creating a thread so I had to remove my code and crop my images using a javascript plugin, instead. Hope that helps.

Can you link to this plugin?

This is the plugin I used. It lets you convert the cropped image to base64. Which you can then upload as a file. http://foliotek.github.io/Croppie/

As i understood we can not mix lang in custom code. So i have some java logic and can not add js implementation to crop images :frowning:

That is correct. In the current implementation of custom business logic languages cannot be mixed.