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

  • Home
  • SEARCH
  • 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 8291473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:08:30+00:00 2026-06-08T13:08:30+00:00

When i try tto copy a store i get a few errors. The errors

  • 0

When i try tto copy a store i get a few errors. The errors are:

 choice:java.io.NotSerializableException: Employee
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.writeObject(Unknown Source)
    at java.util.HashMap.writeObject(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
    at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
    at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
    at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
    at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.writeObject(Unknown Source)
    at FileUtility.save(FileUtility.java:27)
    at MainApp.start(MainApp.java:190)
    at MainApp.main(MainApp.java:16)

Here is also my code:
MainApp

//---------------------------------------------------------------------------------------
//  Name:        Case 7: Store.
//  Description: Choice 7 gives the user an option to copy and read a store
//               using read and write class from Java.
//---------------------------------------------------------------------------------------
            case 7:
                System.out.println("Store");
                EmployeeStore copyMyStore = Store.copy();
                System.out.println(copyMyStore); //print contents to check equality
                //shallow copy would look like this...
                EmployeeStore shallowCopyMyStore;
                //both variables point to same object
                shallowCopyMyStore = Store; 
                //lets store and re-load the mystore object
                FileUtility.save("myStore.store", Store);
                /*EmployeeStore loadedStore 
                            = (EmployeeStore)FileUtility.load("myStore.nmcg");
                System.out.println("\n--- RELOADED STORE CONTENTS ---");
                loadedStore.print();
                //System.out.println("\n(static) Count: "  + EmployeeStore.print);*/


                break;

File Utility

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;


/**
  * <i>Use this class to save and load any type of object (i.e. a container class (e.g. PersonStore), an account, a task, a person)
 *   @author     NMCG
 *   @version    1.0            
*/
public class FileUtility /*serialization - step 2*/
{

    /**
     * @param fileName relative or absolute file path (e.g. "name.txt" or "c:\\temp\\name.txt"
     * @param obj      address of any object to be stored (i.e. a container class (e.g. PersonStore), an account, a task, a person)
     */

    public static void save(String fileName, Object obj)
    {
        try
        {
            FileOutputStream fos = new FileOutputStream(fileName);
            ObjectOutputStream oos = new ObjectOutputStream(fos);

            oos.writeObject(obj);
            oos.flush();
            oos.close();
            fos.close();
        }
        catch(Exception e)
        {
            System.out.println("Something bad happened during the save phase!");
            e.printStackTrace();
        }
    }

    /**
     * @param  fileName relative or absolute file path (e.g. "name.txt" or "c:\\temp\\name.txt")
     * @return Object   address of the object loaded into RAM from file
     */

    public static Object load(String fileName)  // "test.txt"
    {
        Object objectIn = null;
        try
        {
            FileInputStream fis = new FileInputStream(fileName);
            ObjectInputStream ois = new ObjectInputStream(fis);

            objectIn = ois.readObject();

            ois.close();
            fis.close();
        }
        catch(Exception e)
        {
            System.out.println("Something bad happened during the save phase!");
            e.printStackTrace();
        }
        return objectIn;
    }
}

copy

// ---------------------------------------------------------------------------------------
// Name: Store copy.
// ---------------------------------------------------------------------------------------
public EmployeeStore copy()
{
    // instanciate the destination copy and give same name
    EmployeeStore Copy = new EmployeeStore();

    // by specifying the type of the entry in the for loop i.e. <>
    // we don't have to typecast the getKey() and getValue() methods
    // as shown in the commented out line inside the for loop
    for (Map.Entry<String, Employee> entry : map.entrySet()) 
    {
        // getting each key-value and putting into the copy
        // theCopy.add((MovieKey)entry.getKey(), (Movie)entry.getValue());
        Copy.add(entry.getValue());
    }
    // return address of the new MovieStore object
    return Copy;
}
// ---------------------------------------------------------------------------------------
  • 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-06-08T13:08:31+00:00Added an answer on June 8, 2026 at 1:08 pm

    The error message says it all: the Employee class is not serializable. It doesn’t implement the interface java.io.Serializable.

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

Sidebar

Related Questions

When I try and compile this program, I get errors (included below the code)
I am using gmp's mpf_t to try and get very high precision. My range
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try as I might I cannot get my head around what the IteratorIterator class
I had try http://mail.python.org/pipermail/image-sig/2010-June/006313.html , but I get a error still dreampuf@HX:~/hub/lweibo$ python2.7 lweibo.py
Try this piece of code - public class WhitespaceTest { public static void main(String[]
try { if (myBoolean) { while (true) ; } else { System.exit(1); } }
try: html = urlopen('http://glbse.com/api/asset/' + asset.name) except: print 'error while updating the price of
try: recursive_function() except RuntimeError e: # is this a max. recursion depth exceeded exception?
try { JSONArray jArray = new JSONArray(result); for(int i=0;i<jArray.length();i++) { JSONObject json_data = jArray.getJSONObject(i);

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.