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

The Archive Base Latest Questions

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

Disclaimer: I’ve went over many examples and read the docs. This question entails 3

  • 0

Disclaimer: I’ve went over many examples and read the docs.

This question entails 3 classes. My serialized class, a helper class that handles I/O, and an activity for interfacing.

My serialized class looks something like this:

public class EntityPlayer implements Serializable {

private static final long serialVersionUID = -7671612522335708108L;
String name = "foo";

public EntityPlayer() {
    name = "foo";

}

}

My helper class looks like this (this is where the heavy lifting is done):

public class Main {

static Object loadPlayer(Context c, String name) throws IOException,
        ClassNotFoundException {
    FileInputStream f = c.openFileInput(name);
    ObjectInputStream i = new ObjectInputStream(f);
    Object player = i.readObject();
    i.close();
    return player;
}

static void savePlayer(Context c, String name, EntityPlayer player) throws IOException {
    FileOutputStream f = c.openFileOutput(name, Context.MODE_PRIVATE);
    ObjectOutputStream o = new ObjectOutputStream(f);
    o.writeObject(player);
    o.flush();
    o.close();
}

}

and then finally, this is how I’m accesing (in a nut shell):

public class DisplayInteract extends Activity implements OnClickListener {

EntityPlayer player = new EntityPlayer();  //by editing this line, my issue was fixed


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.g_interact);

    player = new EntityPlayer(ID, this);

    try {
        Main.savePlayer(player.name, player);
    } catch (IOException e) {
    }

    try {
        player = (EntityPlayer) Main.loadPlayer("Derp");
    } catch (ClassNotFoundException e) {
    } catch (IOException e) {
    }
}

}

Basically I’m getting a NPE when I make any calls concerning the serialized class after loading it. I know the issue is in the way that I’m saving the file because I can tell that there is no file through the Android file explorer in eclipse. I know the problem also is in how I’m loading the file because (I have no ideal how) I got it to work at one point (it created a file) but I still couldn’t access any of the data without it throwing an NPE (because I wasn’t accessing the class correctly)

  • 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-31T15:23:21+00:00Added an answer on May 31, 2026 at 3:23 pm

    You’re not specifying a path where the file should be saved to.
    Use the openFileOutput() from Context which will save it to your applications data folder.

    FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: This is not actually a programming question, but I feel the audience on
Disclaimer: This is for a homework assignment, but the question is not regarding the
Disclaimer This is not strictly a programming question, but most programmers soon or later
Disclaimer, I'm not a PHP programmer, so you might find this question trivial. That's
Disclaimer : I already asked this question , but without the deployment requirement. I
Disclaimer: this question is purely informational and does not represent an actual problem I'm
Disclaimer: I tried to search for similar question, however this returned about every C++
DISCLAIMER: This is not a real-world example. It is just a theoretical question of
Disclaimer: this question is directly related to my programming homework. My C++ assignment consists
Disclaimer: This question is not about fixing visual studio So, I've used VSS for

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.