Sending an object through a BufferedImage over a socket. Non serializable exception

I am trying to create a client server program that allows users to upload images for their profile. As a result, I have a JFileChooser that takes the path that creates the BufferedImage and UserId and makes an Object from it. I am trying to send this object from my client to my server, but I am getting NotSerializableException.

Here's the class for the object.

import java.awt.image.BufferedImage;
import java.io.Serializable;

public class UserPicture implements Serializable
{
    BufferedImage profilePic;
    int userId;

    public UserPicture(BufferedImage profilePic, int userId)
    {
        this.profilePic=profilePic;
        this.userId=userId;
    }

    public BufferedImage getProfilePic()
    {
        return profilePic;
    }

    public int getUserID()
    {
        return userId;
    }
}

      

I am sending it over a socket like this:

objOutStream.writeObject(theObject);//this is the line throwing the exception
objOutStream.flush();

      

Now I know that BufferedImages can be sent with something like ImageIO.write(image, "jpg", byteArrayOutputStream);

but I'm not really sure how to send it to an object.

Edit: The solution under fixed my exception problem, but now the server side BufferedImage is null ... Is this the result of the solution?

+3


source to share





All Articles