Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6052109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:53:31+00:00 2026-05-23T07:53:31+00:00

I have a Packet class (com.lab.tracking.Packet) in an Android project. I need to send

  • 0

I have a Packet class (com.lab.tracking.Packet) in an Android project. I need to send this packet via UDP to a Server, that has an exactly copy of that Packet class (com.server.serverTracking.Packet).

The android app converts the Packet into a byte stream, and then it sends it to the server. The server receives the byte stream correctly, but when it tries to convert it to a Packet, it throws an exception:

java.lang.ClassNotFoundException: com.lab.tracking.Packet

I understand that. The server is trying to convert this object to a com.lab.tracking.Packet, instead of a com.server.serverTracking.Packet).

The conversion from byte stream to Object is:

    public static Object toObject(byte[] dataReceived) {
    Object obj = null;
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(dataReceived);
        ObjectInputStream ois = new ObjectInputStream(bis);
        obj = ois.readObject();
    } catch (IOException ex) {
        ex.printStackTrace();
    } catch (ClassNotFoundException ex) {   
        ex.printStackTrace();
    }
    return obj;
}

How could I avoid this? Both classes are exactly the same, so I think the problem is in the complete name (or ID, or whatever).

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:53:32+00:00Added an answer on May 23, 2026 at 7:53 am

    To expand on djg’s answer, the problem is that your Packet classes are not “exactly the same” because they are in different packages.

    So the solution would be to get rid of com.server.serverTracking.Packet and move com.lab.tracking.Packet to a common library that both the android app and the server side code depend on.

    That being said, I would recommend against using Java object serialization between and android app and the server. If your Packet changes in any significant way (new member variables, etc.) with new releases, you will likely break all previous versions. At the very least, you should explicitly specify a serialVersionUid.

    A better solution would be to design a structure for the packet byte array, and use a factory class or constructor that parses the byte array into a Java object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an class which should send/receive data in packet form. This class contains
I have a class that my client uses to Get() a packet. The packet
I have classes which are inherited from abstract Packet( this class has abstract method
Let's say I have two classes that look like this: public class ByteFilter {
I have an asynchronous UDP server class with a socket bound on IPAddress.Any, and
I have a class named Packet with this destruct: class Packet { ... RequestPtr
My question is that I have an object class( packet) which contains another object
Lets say I have this class (just as an example): internal class Packet {
In my application I have a PacketList class and Packet class. I'd like to
I have, for my game, a Packet class, which represents network packet and consists

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.