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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:27:03+00:00 2026-05-28T07:27:03+00:00

For a class assignment, I’m required to write an object to a file. Our

  • 0

For a class assignment, I’m required to write an object to a file. Our professor gave us a section of code to complete this, but apparently it’s wrong because I’m getting an error. Here’s my code.

class InvMaintenance {

    //create an OutputStream to write data to a file
    FileOutputStream fos = new FileOutputStream(inven.dat);
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    ObjectOutputStream oos = new ObjectOutputStream(bos);

    final long MAX_SIZE = 100; //constant for array length
    Inventory cInventory = new Inventory(MAX_SIZE); //instantiate Inventory object
    oos.writeObject(cInventory); //write initial Inventory to file  
    public static void main(String[] args) {
        //Output options
        /*  Inventory Maintenance
            1) Add Item
            2) Remove Item
            3) Sell Item
            4) Receive Item
            5) Display Inventory
            6) Quit
            Please Select NUMBER: */

        //switch on options
        //call appropriate method

        oos.writeObject(cInventory);
        oos.close();
    }
}

My error is occuring on the line oos.writeObject(cInventory);

Item.java:150: <identifier> expected
    oos.writeObject(cInventory);            //write initial Inventory to file   
                   ^
Item.java:150: <identifier> expected
    oos.writeObject(cInventory);            //write initial Inventory to file   
                              ^
2 errors

And yes, for some reason it’s saying this is two separate errors that are… exactly the same.

Any help debugging would be appreciated. What’s wrong?

  • 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-28T07:27:04+00:00Added an answer on May 28, 2026 at 7:27 am

    that had to be in the main-method

    //create an OutputStream to write data to a file
    FileOutputStream fos = new FileOutputStream(inven.dat);
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    
    Inventory cInventory = new Inventory(MAX_SIZE); //instantiate Inventory object
    

    changed Code:

    class InvMaintenance {
    
        final static long MAX_SIZE = 100;          //constant for array length
    
        public static void main(String[] args)
        {
            //Output options
                /*  Inventory Maintenance
                    1) Add Item
                    2) Remove Item
                    3) Sell Item
                    4) Receive Item
                    5) Display Inventory
                    6) Quit
                    Please Select NUMBER: */
    
            //switch on options
            //call appropriate method
    
            //create an OutputStream to write data to a file
            FileOutputStream fos = new FileOutputStream(inven.dat);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            ObjectOutputStream oos = new ObjectOutputStream(bos);
    
            Inventory cInventory = new Inventory(MAX_SIZE); //instantiate Inventory object
    
            oos.writeObject(cInventory);
            oos.close();
        }   
    
    }
    

    Hint: change the constant to final static long .. it you use static the values is copied on compile time

    Hint2: take care of the exceptions ..

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

Sidebar

Related Questions

My professor gave my class an assignment today based on object oriented programming in
In my assembly language class, our first assignment was to write a program to
first off this is a class assignment so i would appreciate help but just
I had a simple CUDA problem for a class assignment, but the professor added
Given this model in legacy code, with RoR 2.3.11: class Assignment < ActiveRecord::Base belongs_to
For this assignment I had to create my own string class. I initially wrote
This is a class assignment. I had written some codes which I hope someone
Let me establish that this is part of a class assignment, so I'm definitely
For a Java class assignment I was given a file named LogReader.class to use.
I'm working on a assignment for class so this is only part of the

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.