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
java serialization sockets


source to share


No one has answered this question yet

See similar questions:

0
Java. Sending an object that points to a BufferedImage over a Socket

or similar:

269
Java Serializable Object to Byte Array
8
Sending a screenshot (bufferedImage) over socket in java
3
Theory: C # Sockets, sending Serialized Objects over the network
2
indexoutofboundsexception by sending images over Socket
2
Error with serializable class
1
Sending self-made objects with Java sockets
0
Sending LinkedList objects via ObjectInputStream throws "NotSerializableException" and "StreamCorruptedException" exceptions
0
Use ObjectStreams over Sockets to pass Java Key Object
0
Exception when sending object via rmi arguments
-1
Error writing WriteObject from server to socket



All Articles
Loading...
X
Show
Funny
Dev
Pics