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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:35:05+00:00 2026-06-14T10:35:05+00:00

I have a program in Java with several classes, these being: i) Shape ii)

  • 0

I have a program in Java with several classes, these being:

i) Shape
ii) Square
iii) Rectangle
iv) Circle
v) Triangle
vi) Drawing Canvas
vii) Application

Square, Rectangle, Circle and Triangle all inherit from class Shape

Now, in the Drawing Canvas class, I have two methods, one for writing objects of type Shape to a file and one for reading objects from the file.

This is the code:

The method which saves to the file works perfectly. However, I am having a problem reading the objects from the file and appending them to the Shapes ArrayList.

As it is, the application is given me the error that java.lang.String cannot be cast to shapes_assignment.Shape.

How can I read the text stored in the text file and use it to recreate the objects once more? Thanks 🙂

  • 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-14T10:35:06+00:00Added an answer on June 14, 2026 at 10:35 am

    You need to write a reader that will take the input string, and make a shape out of it. Here is a simple example to show you how this can work, using the Java Date class. Not having your Shape constructors, I can’t write your Shape for you.

    Date today=new Date();
    long var_to_write=today.getTime();
    
    //Save this in to a file, then read it out as long var_in_file
    
    Date previousTime=new Date(var_in_file);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program in java with several Jpanels designed; with certain font and
I have a Java program consisting of several class. Now, I made the interface
So I have this Java program that I use to munch through several terabytes
I have several switch statements in a Java program. My question is, if I
I want to make my program initialization a bit smarter. I have several classes
So I have this Java project made up of several classes, some external JAR
I have several launch configurations in Eclipse each launching the same Java program but
in my java Project I have several classes/java files but is in Menu class
I have a Java program that does several file I/O. Runs fine and get
I have a java program that runs automatically every morning and contains several methods

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.