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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:12:45+00:00 2026-05-18T22:12:45+00:00

friends, i am using following code to write Serializable object to external storage. it

  • 0

friends,

i am using following code to write Serializable object to external storage.

it throws me error java.io.NotSerializableException
even my object is serializable any one guide me what mistake am i doing?

public class MyClass implements Serializable 
{

// other veriable stuff here...
    public String title;
    public String startTime;
    public String endTime;
    public boolean classEnabled;
    public Context myContext;

 public MyClass(Context context,String title, String startTime, boolean enable){
            this.title = title;
            this.startTime = startTime;
            this.classEnabled = enable;
            this.myContext = context;

}

 public boolean saveObject(MyClass obj) {

        final File suspend_f=new File(cacheDir, "test");

            FileOutputStream   fos  = null;
            ObjectOutputStream oos  = null;
            boolean            keep = true;

            try {
                fos = new FileOutputStream(suspend_f);
                oos = new ObjectOutputStream(fos);
                oos.writeObject(obj);   // exception throws here
            }
            catch (Exception e) {
                keep = false;


            }
            finally {
                try {
                    if (oos != null)   oos.close();
                    if (fos != null)   fos.close();
                    if (keep == false) suspend_f.delete();
                }
                catch (Exception e) { /* do nothing */ }
            }


            return keep;


        }

}

and calling from activity class to save it

 MyClass m= new MyClass(this, "hello", "abc", true);
 boolean  result =m.saveObject(m);

any help would be appreciated.

  • 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-18T22:12:45+00:00Added an answer on May 18, 2026 at 10:12 pm

    This fails due to the Context field in your class. Context objects are not serializable.

    Per the Serializable documentation – “When traversing a graph, an object may be encountered that does not support the Serializable interface. In this case the NotSerializableException will be thrown and will identify the class of the non-serializable object.”

    You can either remove the Context field entirely, or apply the transient attribute to the Context field so that it is not serialized.

    public class MyClass implements Serializable 
    {
        ...
        public transient Context myContext;
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Friends, I'm populating a GridView in my asp.net application using following code. GridView grdExport
friends, i have created custom title bar using following titlebar.xml file with code <?xml
friends, i am using following code to display bitmap on screen and having next
friends, i am trying to check internetconnectivity in android and using following code final
Using the following code to display a list of friends from my twitter profile.
friends, i am using following code inside asyncTask public class AsycLoaderFromDbAndMapInjector extends AsyncTask {
I'm using the following code to retrieve the user's friends list and the info
I am trying to get Online Friends by using following code. protected void GetActiveFriends()
Hello friends I am using the following code in my my project. PERMISSIONS: <uses-permission
Hello Friends I am using the following code to show the amount entered in

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.