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 6028557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:45:27+00:00 2026-05-23T04:45:27+00:00

Im trying to write an object i made onto a file using Object output

  • 0

Im trying to write an object i made onto a file using Object output stream and whenever i run the code it thows a NotSerializableException. Please tell me if you see what i did wrong.

Save method:

public static void saveEntity(PhysicsBody b, File f) throws IOException {
    if (!f.exists())
        f.createNewFile();
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
    oos.writeObject(b);
    oos.close();
}

Error output:

java.io.NotSerializableException: PhysicsBody
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at PhysicsUtil.saveEntity(PhysicsUtil.java:15)
at applet.run(applet.java:51)
at java.lang.Thread.run(Unknown Source)

PhysicsBody class:

import java.awt.geom.Point2D;
import java.util.ArrayList;

public class PhysicsBody {

protected float centerX;
protected float centerY;
protected float minX, minY, maxX, maxY;
protected float mass;
protected ArrayList<Vertex> vertices = new ArrayList<Vertex>();
protected ArrayList<Edge> edges = new ArrayList<Edge>();

public PhysicsBody(float mass) {
    this.mass = mass;
}

public void addVertex(Vertex v) {
    if (v != null)
        vertices.add(v);
}

public void addEdge(Edge e) {
    if (e != null)
        edges.add(e);
}

public MinMax projectToAxis(Point2D.Float axis) {
    float dotP = axis.x * vertices.get(0).x + axis.y * vertices.get(0).y;
    MinMax data = new MinMax(dotP, dotP);

    for (int i = 0; i < vertices.size(); i++) {
        dotP = axis.x * vertices.get(i).x + axis.y * vertices.get(i).y;
        data.min = Math.min(data.min, dotP);
        data.max = Math.max(data.max, dotP);
    }
    return data;
}

public void calculateCenter() {
    centerX = centerY = 0;

    minX = 10000.0f;
    minY = 10000.0f;
    maxX = -10000.0f;
    maxY = -10000.0f;

    for (int i = 0; i < vertices.size(); i++) {
        centerX += vertices.get(i).x;
        centerY += vertices.get(i).y;

        minX = Math.min(minX, vertices.get(i).x);
        minY = Math.min(minY, vertices.get(i).y);
        maxX = Math.max(maxX, vertices.get(i).x);
        maxY = Math.max(maxY, vertices.get(i).y);
    }

    centerX /= vertices.size();
    centerY /= vertices.size();
}

}
  • 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-23T04:45:28+00:00Added an answer on May 23, 2026 at 4:45 am

    PhysicsBody must implement java.io.Serializable. Vertex and Edge should also implement it.

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

Sidebar

Related Questions

I'm trying to write some code to find a specific XmlNode object based on
I'm trying to write a function that formats every (string) member/variable in an object,
I have an OLE COM object that trying to write a wrapper for, I
I'm trying to write a blog post which includes a code segment inside a
I'm trying to write some PHP to upload a file to a folder on
So I'm trying to write an Objective-C macro that takes an object and a
I am trying to use the xmlEncoder to write to xml file in net-beans
I'm trying to write a browser helper object.. and sometimes I need to return
I'm trying to write a helper class that represents fields on an object. The
Alright, so I'm trying to write a bunch of Sudoku puzzles to a file.

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.