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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:42:05+00:00 2026-06-09T13:42:05+00:00

To save teleportation points on command, I have an HashMap : public HashMap<Player, Location>

  • 0

To save teleportation points on command, I have an HashMap:

public HashMap<Player, Location> mapHomes = new HashMap<>();

Which is accessed like this:

if(cmd.getName().equalsIgnoreCase("sethome")){
    Location loc = player.getLocation();
    mapHomes.put(player, loc);
    sender.sendMessage("Home set !");
    return true;
}
if(cmd.getName().equalsIgnoreCase("home")){
    Location loc1 = mapHomes.get(player);
    player.teleport(loc1);
    sender.sendMessage("Teleported to home");
    return true;
}
return false;

Since these settings should be kept on restart, I’ve implemented a save method:

public void save(HashMap<Player,Location> mapHome, String path) throws NotSerializableException{
    try{
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(path));
        oos.writeObject(mapHome);
        oos.flush();
        oos.close();
    }catch(Exception e){
        e.printStackTrace();
    }
}

But it’s not working. It throws NotSerializableException.

I think the main problem is Player and Location are not serializable types, so what should I do to write this HashMap?

  • 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-09T13:42:06+00:00Added an answer on June 9, 2026 at 1:42 pm

    HashMap is already Serializable.

    The problem is that the objects inside the map are not, so you’ll have to make them serializable, too.

    public class SerializedPlayer extends Player implements Serializable {
        public SerializedPlayer() {}
        public SerializedPlayer(Player playerToClone) {
            this.setField1(playerToClone.getField1());
            // Set all the fields
        }
    }
    

    When adding to the map:

    map.put(new SerializedPlayer(player), new SerializedLocation(location));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I save bitmap as jpg file. The source code is: imageView = new ImageView(this);
i save a user like this in doctrine: $user = User(); $user->name = 'peter';
I Save An onject into a xml file with serialize like this: FileStream stream
I save a matrix to a file like this: save(filepath, 'mtrx', '-ascii'); Is there
//Save new category information $('.save_cat').live('click', function() { cat_id = $(this).attr(id).slice(4); cat_name = $(this).parent().prev().prev().children('.cat_name_edit').val(); sort_order
i save some ressources in the res/raw directory which i then would like to
I save picture from UIImagePicker this way: Save picture in file and then I
I save picture from UIImagePicker this way: Save picture in file and then I
I save in a file some info about users (like number of times user
To save some space in my code, I made this typedef: typedef clients.members.at(selectedTab) currentMember;

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.