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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:44:35+00:00 2026-05-23T01:44:35+00:00

I am saving a couple of things when I exit an Activity. First in

  • 0

I am saving a couple of things when I exit an Activity.
First in an object and the second is an int value.

It saves ok but when I try to read back I get an EOFException when trying to get the second item.

    private void saveData(){
        FileOutputStream saveFile = null;
        try {
            saveFile = this.openFileOutput(STATE_SAVE_FILE_NAME, Context.MODE_PRIVATE);
            ObjectOutput output = new ObjectOutputStream(saveFile);
            output.writeObject(game); 
            output.write(ScoringForScoreloop.getScore());
            output.close();
        }
        catch (Exception ex) {
            ex.printStackTrace();
        } 
        finally {
                try {
                    saveFile.close();
                } 
                catch (Exception ex) {
                    ex.printStackTrace();
                } 
        }

    } 

private void restoreData(){
        FileInputStream restoreFile = null;
        try {
                try {
                    restoreFile = this.openFileInput(STATE_SAVE_FILE_NAME);
                } 
                catch (FileNotFoundException e) {
                    inGame = false;
                    return;     // If no file then ok - we will start a new game
                }

                ObjectInput input = new ObjectInputStream(restoreFile);
                game = (GameControl) input.readObject();
                ScoringForScoreloop.setScore(input.readInt());
                inGame = (game!=null);
        } catch (Exception e) {
            inGame = false;
            return;     // If error then we will start a new game
        }
        finally {
                try {
                    restoreFile.close();
                    this.deleteFile(STATE_SAVE_FILE_NAME);   // delete it so we don't restore from it again
                } 
                catch (Exception   ex) {
                    inGame = false;
                    return;     // If error then we will start a new game
                }
        }

    }
  • 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-23T01:44:35+00:00Added an answer on May 23, 2026 at 1:44 am

    I’ve never used these classes in Java before, but I’ll hazard a guess. I suspect the problem is a difference between int and Integer in Java.

    In the write code, have you tried replacing

    output.write(ScoringForScoreloop.getScore());
    

    with

    output.writeInt(ScoringForScoreloop.getScore());
    

    That way you should be symmetrical on read and write in terms of type handling.

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

Sidebar

Related Questions

Saving a Word 2003 document to XML and then back results in a reduced
After saving a String value into memcached using the Danga client, I attempted to
I am saving an XMLDocument object to disk using the Save (string) function .
I am saving a TimeSpan (from .NET) value in my db as BIGINT in
This has been asked a couple of times, but none provide coded test cases.
I've spent the past couple days going over a handful of Django/AJAX tutorials, but
I have been using elem.removeChild() to remove elements from my document, but saving a
I am getting an NSValidationErrorObject when saving my managed object context. I am trying
I've read about and experimented with the Scala 2.9 try...catch feature, and it has
I have a situation where I need to check a couple of things before

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.