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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:22:31+00:00 2026-05-10T18:22:31+00:00

I want to save and store simple mail objects via serializing, but I get

  • 0

I want to save and store simple mail objects via serializing, but I get always an error and I can’t find where it is.

package sotring; import java.io.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*;  import com.sun.org.apache.bcel.internal.generic.INEG;  public class storeing {      public static void storeMail(Message[] mail){         try {             ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream('mail.ser'));             out.writeObject(mail);             out.flush();             out.close();          } catch (IOException e) {         }        }          public static Message[] getStoredMails(){       try      {          ObjectInputStream in = new ObjectInputStream(new FileInputStream('mail.ser'));         Message[] array = (Message[]) in.readObject() ;         for (int i=0; i< array.length;i++)             System.out.println('EMail von:'+ array[i].getSender() + ' an ' + array[i].getReceiver()+ ' Emailbetreff: '+ array[i].getBetreff() + ' Inhalt: ' + array[i].getContent());          System.out.println('Size: '+array.length);  //return array;         in.close();         return array;          }      catch(IOException ex)      {         ex.printStackTrace();         return null;      }      catch(ClassNotFoundException ex)      {         ex.printStackTrace();         return null;      }   }      public static void main(String[] args) {         User user1 = new User('User1', 'geheim');         User user2 = new User('User2', 'geheim');          Message email1 = new Message(user1.getName(), user2.getName(), 'Test', 'Fooobaaaar');         Message email2 = new Message(user1.getName(), user2.getName(), 'Test2', 'Woohoo');         Message email3 = new Message(user1.getName(), user2.getName(), 'Test3', 'Okay =) ');         Message [] mails = {email1, email2, email3};         storeMail(mails);         Message[] restored = getStoredMails();;              } } 

Here are the user and message class

public class Message implements Serializable{      static final long serialVersionUID = -1L;      private String receiver;  //Empfänger     private String sender;  //Absender     private String Betreff;     private String content;     private String timestamp;      private String getDateTime() {         DateFormat dateFormat = new SimpleDateFormat('yyyy/MM/dd HH:mm:ss');         Date date = new Date();         return dateFormat.format(date);     }      Message (String receiver, String sender, String Betreff, String content) {         this.Betreff= Betreff;         this.receiver = receiver;         this.sender = sender;         this.content = content;         this.timestamp = getDateTime();      }      Message() {  // Just for loaded msg      }      public String getReceiver() {         return receiver;     }      public void setReceiver(String receiver) {         this.receiver = receiver;     }      public String getSender() {         return sender;     }      public void setSender(String sender) {         this.sender = sender;     }      public String getBetreff() {         return Betreff;     }      public void setBetreff(String betreff) {         Betreff = betreff;     }      public String getContent() {         return content;     }     public String getTime() {         return timestamp;     }     public void setContent(String content) {         this.content = content;     }  }  public class User implements Serializable{      static final long serialVersionUID = -1L;     private String username;  //unique Username     private String ipadress;  //changes everytime     private String password;  //Password     private int unreadMsg;    //Unread Messages     private static int usercount;     private boolean online;      public String getName(){         return username;     }     public boolean Status() {         return online;     }      public void setOnline() {         this.online = true;     }     public void setOffline() {         this.online = false;     }      User(String username,String password){         if (true){             this.username = username;             this.password = password;             usercount++;          } else System.out.print('Username not availiable');      }      public void changePassword(String newpassword){         password = newpassword;     }      public void setIP(String newip){         ipadress = newip;     }      public String getIP(){         if (ipadress.length() >= 7){             return ipadress;         } else return 'ip address not set.';     }        public int getUnreadMsg() {         return unreadMsg;     }    } 

Here is the exception:

exception in thread 'main' java.lang.Error: Unresolved compilation problem: This method must return a result of type Message[] at sotring.storeing.getStoredMails(storeing.java:22) at sotring.storeing.main(storeing.java:57)

THANK YOU FOR YOUR HELP!!!!!!!!!!!

  • 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. 2026-05-10T18:22:32+00:00Added an answer on May 10, 2026 at 6:22 pm

    If an exception occurs, you never get to the return statement in getStoredMails. You need to either throw the exception you catch (possibly wrapping it in another more descriptive exception) or just return null at the end of the method. It really depends on what you want to do if there’s an error.

    Oh, and your in.close() should be in a finally block. Otherwise, it is possible that you could read the data fine but then throw it away if you can’t close the stream.

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

Sidebar

Ask A Question

Stats

  • Questions 86k
  • Answers 86k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You cannot achieve this with ForEach. May 11, 2026 at 5:19 pm
  • Editorial Team
    Editorial Team added an answer Something like: find -type f |xargs sed -i '$s/[[:space:]]+$//' That… May 11, 2026 at 5:19 pm
  • Editorial Team
    Editorial Team added an answer For binding complex objects involving collections, check out my answer… May 11, 2026 at 5:19 pm

Related Questions

I'm making a simple 2 player game in XNA and started looking into saving
I'm working on a project which stores single images and text files in one
I'm writing a little desktop app that should be able to encrypt a data
I have a database with a report table. This table represents report data, and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.