Sam Bombo
Sam Bombo

Reputation: 25

array of HashMaps not deserializing

I have a JavaFX program that takes input from the user and saves it to a serialization file of the user's choice. Any of the files saved by the user can be de-serialized, edited, or viewed. This is all done by storing the data in hash maps and serializing an array of the hashmaps.

What is happening is the data is being collected correctly, but not able to be recovered if you exit the program and restart. I've checked the serialization file and it seems to be saving, but not loading.

This a very large JavaFX program and I've only included the three classes that use/deal with the hash maps. I believe that this is more a data structures problem, with the way I possibly set up the HashMaps, and less of a JavaFX problem.

Here is the class that the Hashmaps are created:

`package CanavanCalculator;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;

import javafx.scene.control.ComboBox;

public class Data extends Start {
    // public static final long serialVersionUID = -2843350657533110180L;
    // for hashmaps, use index integer for plate Appearence number

    public HashMap<Integer, Integer> Balls = new HashMap<Integer, Integer>(); 
    public HashMap<Integer, Integer> Strikes = new HashMap<Integer, Integer>();
    public HashMap<Integer, Integer> Pitches = new HashMap<Integer, Integer>();
    public HashMap<Integer, String> PitchType = new HashMap<Integer, String>();
    public HashMap<Integer, String> PitchLocation = new HashMap<Integer, String>();
    public HashMap<Integer, String> HitQuality = new HashMap<Integer, String>();
    public HashMap<Integer, String> HitType = new HashMap<Integer, String>();
    public HashMap<Integer, String> HitDirection = new HashMap<Integer, String>();
    public HashMap<Integer, String> PitcherNames = new HashMap<Integer, String>();
    public HashMap<Integer, Boolean> PitcherOrientation = new HashMap<Integer, Boolean>();
    // true = Right handed; false = left handed
    public static HashMap<Integer, String> Opponent = new HashMap<Integer, String>();
    public static HashMap<Integer, String> TeamList = new HashMap<Integer, String>();
    public  HashMap[] arr = { Balls, Strikes, Pitches, PitchType, PitchLocation, HitQuality, HitType, HitDirection,
            PitcherNames, PitcherOrientation };
    //public String[] str= {"Balls","Strikes","Pitches","PitchType","PitchLocation","HitQuality","HitType","HitDirection","PitcherNames","PitcherOrientation"}; 

    static HashMap<Integer, String> oldList = new HashMap<Integer, String>();

    public static String temp = "null";

    public  void debug() {
        for (HashMap hshmp : arr) {
            System.out.println(hshmp);
        }
    }


    public String Percent(int dividend, int divisor) {
        double d = (double) dividend / divisor;
        if (dividend == 0 && divisor == 0) {
            return "0.0%";
        } else {
            d *= 100;
            String returned = d + "%";
            return returned;
        }
    }

    public static String mergedata(int freq, String percent) {
        return freq + ": " + percent;
    }


    public void save(String Name) {
        if (Name != null) {
            try (FileOutputStream fos = new FileOutputStream(Name+".ser");
                    ObjectOutputStream OOs = new ObjectOutputStream(fos)) {
                System.out.println(arr);
                OOs.writeObject(arr);
                debug();
            } catch (FileNotFoundException fnfe) {
                fnfe.printStackTrace();
                System.out.println(fnfe.getMessage());
            } catch (IOException Io) {
                Io.printStackTrace();
                System.out.println(Io.getMessage());
            }
        }
    }


    public void open(String Name) {
        try (FileInputStream fis = new FileInputStream(Name+".ser");
                ObjectInputStream ois = new ObjectInputStream(fis)) {
             arr = (HashMap[]) ois.readObject();
            temp = Name;
            debug();
        } catch (IOException ioe) {
            ioe.printStackTrace();
            System.out.print(ioe.getMessage());
        } catch (ClassNotFoundException cnfe) {
            System.out.println(cnfe.getMessage());
            cnfe.printStackTrace();
        }
    }


    public static void saveteamname() {
        try (FileOutputStream fos = new FileOutputStream(toFile("Team0ra"));
                ObjectOutputStream OOs = new ObjectOutputStream(fos)) {
            OOs.writeObject(TeamList);
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
            System.out.println(fnfe.getMessage());
        } catch (IOException Io) {
            Io.printStackTrace();
            System.out.println(Io.getMessage());
        }
    }

    public void loadteamname() {
        try {
            FileInputStream fis = new FileInputStream(toFile("Team0ra"));
            ObjectInputStream ois = new ObjectInputStream(fis);
            clear();
            TeamList = (HashMap<Integer, String>) ois.readObject();
            System.out.println(TeamList);
        } catch (IOException ioe) {
            ioe.printStackTrace();
            System.out.print(ioe.getMessage());
        } catch (ClassNotFoundException cnfe) {
            TeamList.put(1, "ME");
            saveteamname();
            System.out.println(cnfe.getMessage());
            cnfe.printStackTrace();
        }
    }

    public void clear() {
        for (HashMap hash : arr) {
            hash.clear();
        }
    }

    public static String toFile(String name/* hitters from the hashmap */) {
        return name + ".ser";
    }

    public static  void addTeamListtobox(ComboBox<String> cb) {
        System.out.println(TeamList);
        for (int i = 1; i <= TeamList.size(); i++) {
            if (TeamList.get(i) != null) {
                cb.getItems().add(TeamList.get(i));
            }
        }

    }

    public static int countif(HashMap Map, String check, HashMap Map1, String check1) {
        int returne = 0;
        for (int i = -1; i <= Map.size(); i++) {
            if (Map.get(i) != null && Map1.get(i) != null) {
                if (((String) Map.get(i)).equalsIgnoreCase(check) && ((String) Map1.get(i)).equalsIgnoreCase(check1)) {
                    returne++;
                }
            }
        }
        return returne;

    }

    public static  int countif(HashMap Map, int check, HashMap Map1, String check1) {
        int returne = 0;
        for (int i = -1; i <= Map.size(); i++) {
            if (Map.get(i) != null && Map1.get(i) != null) {
                if (((int) Map.get(i)) == check && ((String) Map1.get(i)).equalsIgnoreCase(check1)) {
                    returne++;
                }
            }
        }
        return returne;

    }

    public static int countif(HashMap Map, int check, HashMap Map1, int check1, HashMap map2, String check2) {
        int returne = 0;
        for (int i = -1; i <= Map.size(); i++) {
            if (Map.get(i) != null && Map1.get(i) != null) {
                if (((int) Map.get(i)) == check && ((int) Map1.get(i)) == check1
                        && ((String) map2.get(i)).equals(check2)) {
                    returne++;
                }
            }
        }
        return returne;

    }

    public static  int countif(HashMap Map, int check, HashMap Map1, int check1) {
        int returne = 0;
        for (int i = -1; i <= Map.size(); i++) {
            if (Map.get(i) != null && Map1.get(i) != null) {
                if ((int) Map.get(i) == check && (int) Map1.get(i) == check1) {
                    returne++;
                }
            }
        }
        return returne;

    }

    public static int countif(HashMap Map, int check) {
        int returne = 0;
        for (int i = -1; i <= Map.size(); i++) {
            if (Map.get(i) != null) {
                if ((int) Map.get(i) == check) {
                    returne++;
                }
            }
        }
        return returne;

    }

    public static int countif(HashMap Map, String check) {
        int returne = 0;
        for (int i = -1; i <= Map.size(); i++) {
            if (Map.get(i) != null) {
                if (((String) Map.get(i)).equalsIgnoreCase(check)) {
                    returne++;
                }
            }
        }
        return returne;

    }
}
`

Here is the first controller:

 package ------;
    import java.net.URL;
    import java.util.ResourceBundle;
    import javafx.event.ActionEvent;
    import javafx.fxml.FXML;
    import javafx.fxml.Initializable;
    import javafx.scene.control.Button;
    import javafx.scene.control.ComboBox;
    import javafx.scene.control.TextField; 

public class Controller extends Data implements Initializable {

    // variables for calculations
    protected boolean contact;
    protected int ex1;
    // variables from FXes
    @FXML
    ComboBox<String> InPitchType;
    @FXML
    ComboBox<String> InPitchLocation;
    @FXML
    ComboBox<String> InHitQuality;
    @FXML
    ComboBox<String> InHitType;
    @FXML
    ComboBox<String> InHitDirection;
    @FXML
    ComboBox<String> InPitcherHand;
    @FXML
    ComboBox<String> InHitter;
    @FXML
    TextField PitcherName;
    @FXML
    TextField InPitcher;
    @FXML
    TextField InBalls;
    @FXML
    TextField InStrikes;
    @FXML
    Button AddData;
    @FXML
    TextField InOpponent;
    protected void closesafe() {// not finished
        // create the new files
        save(temp);
        debug();
        int newent = TeamList.size() - oldList.size();
        for (int i = 0; i <= newent; i++) {
            if (null != TeamList.get(oldList.size() + i)) {
                save(TeamList.get(oldList.size() + i));
            }

        }
        saveteamname();
        System.out.println(TeamList);
        stage.close();
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        InPitchType.getItems().addAll("Change Up", "FastBall", "CurveBall", "Slider");
        InPitchLocation.getItems().addAll("Ball-Inside-High", "Ball-Inside-low", "Ball-Outside-High",
                "Ball-Outside-Low", "Ball-Middle Inside-High", "Ball-Middle Outside-High", "Ball-Inside-Low",
                "Ball-Outside-Low", "Strike-Inside-High", "Strike-Inside-Low", "Strike-Outside-Low",
                "Strike-Outside-High", "Strike-Center", "Strike-Center-High", "Strike-Center-Low");
        InHitQuality.getItems().addAll("Hard Hit", "Routine Hit", "Weak Hit", "Standing Strikeout", "Strikeout", "Walk",
                "Hit By Pitch");
        InHitType.getItems().addAll("Grounder", "Line-Drive", "Fly");
        InHitDirection.getItems().addAll("Pitcher", "Catcher", "First Base", "Second Base", "Shortstop", "Third Base",
                "Right Field", "Center Field", "Left Field");
        InPitcherHand.getItems().addAll("Left Handed", "Right Handed");
        loadteamname();
        oldList = TeamList;
        addTeamListtobox(InHitter);
        stage.setOnCloseRequest(e -> closesafe());
        System.out.println(TeamList);
    }

    // event handlers
    public void AddValue(ActionEvent actionevent) {
        ex1 = Pitches.size() + 1;
        System.out.println(ex1);
        try {
            InBalls.getText();
            InStrikes.getText();
        } catch (NumberFormatException nfe) {
            System.out.println(nfe.getMessage());
            nfe.printStackTrace();
        }
        Balls.put(ex1, Integer.parseInt(InBalls.getText()));
        Strikes.put(ex1, Integer.parseInt(InStrikes.getText()));
        Pitches.put(ex1, Integer.parseInt(InStrikes.getText()) + Integer.parseInt(InBalls.getText()));
        PitchType.put(ex1, InPitchType.getValue());
        PitchLocation.put(ex1, InPitchLocation.getValue());
        HitQuality.put(ex1, InHitQuality.getValue());
        if (contact) {
            // if the ball was actually hit, then add the other stuff
            HitType.put(ex1, InHitType.getValue());
            HitDirection.put(ex1, InHitDirection.getValue());
        } else {// if not, dont
            HitType.put(ex1, null);
            HitDirection.put(ex1, null);
        }
        debug();
        PitcherNames.put(ex1, PitcherName.getText());
        Opponent.put(ex1, InOpponent.getText());
        if (InPitcherHand != null && InPitcherHand.getValue() == "Left Handed") {
            PitcherOrientation.put(ex1, false);
        } else if (InPitcherHand != null && InPitcherHand.getValue() == "Right Handed") {
            PitcherOrientation.put(ex1, true);
        }
        System.out.println("Ran and added");
//      InBalls.clear();
//      InStrikes.clear();
//      PitcherNames.clear();
//      Opponent.clear();
    }

    public void GoToAbout(ActionEvent actionevent) {
        gotoabout();
    }

    public void GoToData(ActionEvent actionevent) {
        gotodata();
    }

    public void CheckValueType(ActionEvent actionevent) {
        if (InHitQuality.getValue().equals("Hit By Pitch") || (InHitType.getValue().equals("Walk")
                || (InHitType.getValue().equals("Strikeout") || (InHitType.getValue().equals("Standing Strikeout"))))) {
            contact = false;
        } else {
            contact = true;
        }
    }

    public void CheckHitter(ActionEvent actionevent) {
        save(temp);
        System.out.println("before:");
        debug();
        if (InHitter.getValue() != null) {
            open(InHitter.getValue());
            System.out.println("after:");
            debug();
        }
    }

}

Then here is the last controller:

package CanavanCalculator;

import java.net.URL;
import java.util.HashMap;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.text.Text;

public class contOutput extends Data implements Initializable {
    protected void closesafe() {// not finished
        // create the new files
        save(temp);
        debug();
        int newent = TeamList.size() - oldList.size();
        for (int i = 0; i <= newent; i++) {
            if (null != TeamList.get(oldList.size() + i)) {
                save(TeamList.get(oldList.size() + i));
            }

        }
        saveteamname();
        System.out.println(TeamList);
        stage.close();
    }
    @FXML
    Button AddData;
    @FXML
    ComboBox<String> ListOTeam;
    // formula for aiming Text Fields:
    // page,column name,row number
    /* Number of Pitches page */@FXML
    Text NPF1, NPF2, NPF3, NPF4, NPF5, NPF6, NPHH1, NPHH2, NPHH3, NPHH4, NPHH5, NPHH6, NPRH1, NPRH2, NPRH3, NPRH4,
            NPRH5, NPRH6, NPWH1, NPWH2, NPWH3, NPWH4, NPWH5, NPWH6, NPSS1, NPSS2, NPSS3, NPSS4, NPSS5, NPSS6, NPS1,
            NPS2, NPS3, NPS4, NPS5, NPS6, NPW1, NPW2, NPW3, NPW4, NPW5, NPW6, NPHBP1, NPHBP2, NPHBP3, NPHBP4, NPHBP5,
            NPHBP6, NPLD1, NPLD2, NPLD3, NPLD4, NPLD5, NPLD6, NPG1, NPG2, NPG3, NPG4, NPG5, NPG6, NPFL1, NPFL2, NPFL3,
            NPFL4, NPFL5, NPFL6;
    Text[][] NP = { { NPF1, NPF2, NPF3, NPF4, NPF5, NPF6 }, { NPHH1, NPHH2, NPHH3, NPHH4, NPHH5, NPHH6 },
            { NPRH1, NPRH2, NPRH3, NPRH4, NPRH5, NPRH6 }, { NPWH1, NPWH2, NPWH3, NPWH4, NPWH5, NPWH6 },
            { NPSS1, NPSS2, NPSS3, NPSS4, NPSS5, NPSS6 }, { NPS1, NPS2, NPS3, NPS4, NPS5, NPS6 },
            { NPW1, NPW2, NPW3, NPW4, NPW5, NPW6 }, { NPHBP1, NPHBP2, NPHBP3, NPHBP4, NPHBP5, NPHBP6 },
            { NPLD1, NPLD2, NPLD3, NPLD4, NPLD5, NPLD6 }, { NPG1, NPG2, NPG3, NPG4, NPG5, NPG6 },
            { NPFL1, NPFL2, NPFL3, NPFL4, NPFL5, NPFL6 } };

    /* Count */@FXML
    Text CTF1, CTF2, CTF3, CTF4, CTF5, CTF6, CTF7, CTF8, CTF9, CTF10, CTF11, CTF12, CTHH1, CTHH2, CTHH3, CTHH4, CTHH5,
            CTHH6, CTHH7, CTHH8, CTHH9, CTHH10, CTHH11, CTHH12, CTRH1, CTRH2, CTRH3, CTRH4, CTRH5, CTRH6, CTRH7, CTRH8,
            CTRH9, CTRH10, CTRH11, CTRH12, CTWH1, CTWH2, CTWH3, CTWH4, CTWH5, CTWH6, CTWH7, CTWH8, CTWH9, CTWH10,
            CTWH11, CTWH12, CTSS1, CTSS2, CTSS3, CTSS4, CTSS5, CTSS6, CTSS7, CTSS8, CTSS9, CTSS10, CTSS11, CTSS12, CTS1,
            CTS2, CTS3, CTS4, CTS5, CTS6, CTS7, CTS8, CTS9, CTS10, CTS11, CTS12, CTW1, CTW2, CTW3, CTW4, CTW5, CTW6,
            CTW7, CTW8, CTW9, CTW10, CTW11, CTW12, CTHBP1, CTHBP2, CTHBP3, CTHBP4, CTHBP5, CTHBP6, CTHBP7, CTHBP8,
            CTHBP9, CTHBP10, CTHBP11, CTHBP12, CTLD1, CTLD2, CTLD3, CTLD4, CTLD5, CTLD6, CTLD7, CTLD8, CTLD9, CTLD10,
            CTLD11, CTLD12, CTGD1, CTGD2, CTGD3, CTGD4, CTGD5, CTGD6, CTGD7, CTGD8, CTGD9, CTGD10, CTGD11, CTGD12,
            CTFL1, CTFL2, CTFL3, CTFL4, CTFL5, CTFL6, CTFL7, CTFL8, CTFL9, CTFL10, CTFL11, CTFL12;
    Text[][] CT = { { CTF1, CTF2, CTF3, CTF4, CTF5, CTF6, CTF7, CTF8, CTF9, CTF10, CTF11, CTF12 },
            { CTHH1, CTHH2, CTHH3, CTHH4, CTHH5, CTHH6, CTHH7, CTHH8, CTHH9, CTHH10, CTHH11, CTHH12 },
            { CTRH1, CTRH2, CTRH3, CTRH4, CTRH5, CTRH6, CTRH7, CTRH8, CTRH9, CTRH10, CTRH11, CTRH12 },
            { CTWH1, CTWH2, CTWH3, CTWH4, CTWH5, CTWH6, CTWH7, CTWH8, CTWH9, CTWH10, CTWH11, CTWH12 },
            { CTSS1, CTSS2, CTSS3, CTSS4, CTSS5, CTSS6, CTSS7, CTSS8, CTSS9, CTSS10, CTSS11, CTSS12 },
            { CTS1, CTS2, CTS3, CTS4, CTS5, CTS6, CTS7, CTS8, CTS9, CTS10, CTS11, CTS12 },
            { CTW1, CTW2, CTW3, CTW4, CTW5, CTW6, CTW7, CTW8, CTW9, CTW10, CTW11, CTW12 },
            { CTHBP1, CTHBP2, CTHBP3, CTHBP4, CTHBP5, CTHBP6, CTHBP7, CTHBP8, CTHBP9, CTHBP10, CTHBP11, CTHBP12 },
            { CTLD1, CTLD2, CTLD3, CTLD4, CTLD5, CTLD6, CTLD7, CTLD8, CTLD9, CTLD10, CTLD11, CTLD12 },
            { CTGD1, CTGD2, CTGD3, CTGD4, CTGD5, CTGD6, CTGD7, CTGD8, CTGD9, CTGD10, CTGD11, CTGD12 },
            { CTFL1, CTFL2, CTFL3, CTFL4, CTFL5, CTFL6, CTFL7, CTFL8, CTFL9, CTFL10, CTFL11, CTFL12 } };

    /* Pitch Type */
    @FXML
    Text PTF1, PTF2, PTF3, PTF4, PTHH1, PTHH2, PTHH3, PTHH4, PTRH1, PTRH2, PTRH3, PTRH4, PTWH1, PTWH2, PTWH3, PTWH4,
            PTSS1, PTSS2, PTSS3, PTSS4, PTS1, PTS2, PTS3, PTS4, PTW1, PTW2, PTW3, PTW4, PTHBP1, PTHBP2, PTHBP3, PTHBP4,
            PTLD1, PTLD2, PTLD3, PTLD4, PTGD1, PTGD2, PTGD3, PTGD4, PTFL1, PTFL2, PTFL3, PTFL4;
    Text[][] PT = { { PTF1, PTF2, PTF3, PTF4 }, { PTHH1, PTHH2, PTHH3, PTHH4 }, { PTRH1, PTRH2, PTRH3, PTRH4 },
            { PTWH1, PTWH2, PTWH3, PTWH4 }, { PTSS1, PTSS2, PTSS3, PTSS4 }, { PTS1, PTS2, PTS3, PTS4 },
            { PTW1, PTW2, PTW3, PTW4 }, { PTHBP1, PTHBP2, PTHBP3, PTHBP4 }, { PTLD1, PTLD2, PTLD3, PTLD4 },
            { PTGD1, PTGD2, PTGD3, PTGD4 }, { PTFL1, PTFL2, PTFL3, PTFL4 } };
    /* Pitch Location */
    @FXML
    Text PLF1, PLF2, PLF3, PLF4, PLF5, PLF6, PLF7, PLF8, PLF9, PLF10, PLF11, PLF12,PLF13,PLF14,PLF15, PLHH1, PLHH2, PLHH3, PLHH4, PLHH5,
            PLHH6, PLHH7, PLHH8, PLHH9, PLHH10, PLHH11, PLHH12,PLHH13,PLHH14,PLHH15, PLRH1, PLRH2, PLRH3, PLRH4, PLRH5, PLRH6, PLRH7, PLRH8,
            PLRH9, PLRH10, PLRH11, PLRH12,PLRH13,PLRH14,PLRH15, PLWH1, PLWH2, PLWH3, PLWH4, PLWH5, PLWH6, PLWH7, PLWH8, PLWH9, PLWH10,
            PLWH11, PLWH12,PLWH13,PLWH14,PLWH15, PLSS1, PLSS2, PLSS3, PLSS4, PLSS5, PLSS6, PLSS7, PLSS8, PLSS9, PLSS10, PLSS11, PLSS12,PLSS13,PLSS14,PLSS15, PLS1,
            PLS2, PLS3, PLS4, PLS5, PLS6, PLS7, PLS8, PLS9, PLS10, PLS11, PLS12,PLS13,PLS14,PLS15, PLW1, PLW2, PLW3, PLW4, PLW5, PLW6,
            PLW7, PLW8, PLW9, PLW10, PLW11, PLW12,PLW13,PLW14,PLW15, PLHBP1, PLHBP2, PLHBP3, PLHBP4, PLHBP5, PLHBP6, PLHBP7, PLHBP8,
            PLHBP9, PLHBP10, PLHBP11, PLHBP12,PLHBP13,PLHBP14,PLHBP15, PLLD1, PLLD2, PLLD3, PLLD4, PLLD5, PLLD6, PLLD7, PLLD8, PLLD9, PLLD10,
            PLLD11, PLLD12,PLLD13,PLLD14,PLLD15, PLGD1, PLGD2, PLGD3, PLGD4, PLGD5, PLGD6, PLGD7, PLGD8, PLGD9, PLGD10, PLGD11, PLGD12,PLGD13,PLGD14,PLGD15,
            PLFL1, PLFL2, PLFL3, PLFL4, PLFL5, PLFL6, PLFL7, PLFL8, PLFL9, PLFL10, PLFL11, PLFL12,PLFL13,PLFL14,PLFL15;
    Text[][] PL = { { PLF1, PLF2, PLF3, PLF4, PLF5, PLF6, PLF7, PLF8, PLF9, PLF10, PLF11, PLF12,PLF13,PLF14,PLF15 },
            { PLHH1, PLHH2, PLHH3, PLHH4, PLHH5, PLHH6, PLHH7, PLHH8, PLHH9, PLHH10, PLHH11, PLHH12,PLHH13,PLHH14,PLHH15 },
            { PLRH1, PLRH2, PLRH3, PLRH4, PLRH5, PLRH6, PLRH7, PLRH8, PLRH9, PLRH10, PLRH11, PLRH12,PLRH13,PLRH14,PLRH15 },
            { PLWH1, PLWH2, PLWH3, PLWH4, PLWH5, PLWH6, PLWH7, PLWH8, PLWH9, PLWH10, PLWH11, PLWH12,PLWH13,PLWH14,PLWH15 },
            { PLSS1, PLSS2, PLSS3, PLSS4, PLSS5, PLSS6, PLSS7, PLSS8, PLSS9, PLSS10, PLSS11, PLSS12,PLSS13,PLSS14,PLSS15 },
            { PLS1, PLS2, PLS3, PLS4, PLS5, PLS6, PLS7, PLS8, PLS9, PLS10, PLS11, PLS12,PLS13,PLS14,PLS15 },
            { PLW1, PLW2, PLW3, PLW4, PLW5, PLW6, PLW7, PLW8, PLW9, PLW10, PLW11, PLW12,PLW13,PLW14,PLW15 },
            { PLHBP1, PLHBP2, PLHBP3, PLHBP4, PLHBP5, PLHBP6, PLHBP7, PLHBP8, PLHBP9, PLHBP10, PLHBP11, PLHBP12 ,PLHBP13,PLHBP14,PLHBP15},
            { PLLD1, PLLD2, PLLD3, PLLD4, PLLD5, PLLD6, PLLD7, PLLD8, PLLD9, PLLD10, PLLD11, PLLD12,PLLD13,PLLD14,PLLD15 },
            { PLGD1, PLGD2, PLGD3, PLGD4, PLGD5, PLGD6, PLGD7, PLGD8, PLGD9, PLGD10, PLGD11, PLGD12,PLGD13,PLGD14,PLGD15 },
            { PLFL1, PLFL2, PLFL3, PLFL4, PLFL5, PLFL6, PLFL7, PLFL8, PLFL9, PLFL10, PLFL11, PLFL12,PLFL13,PLFL14,PLFL15 } };
    /* Hit Direction */
    @FXML
    Text HDF1, HDF2, HDF3, HDF4, HDF5, HDF6, HDF7, HDF8, HDF9, HDHH1, HDHH2, HDHH3, HDHH4, HDHH5, HDHH6, HDHH7, HDHH8,
            HDHH9, HDRH1, HDRH2, HDRH3, HDRH4, HDRH5, HDRH6, HDRH7, HDRH8, HDRH9, HDWH1, HDWH2, HDWH3, HDWH4, HDWH5,
            HDWH6, HDWH7, HDWH8, HDWH9, HDSS1, HDSS2, HDSS3, HDSS4, HDSS5, HDSS6, HDSS7, HDSS8, HDSS9, HDS1, HDS2, HDS3,
            HDS4, HDS5, HDS6, HDS7, HDS8, HDS9, HDW1, HDW2, HDW3, HDW4, HDW5, HDW6, HDW7, HDW8, HDW9, HDHBP1, HDHBP2,
            HDHBP3, HDHBP4, HDHBP5, HDHBP6, HDHBP7, HDHBP8, HDHBP9, HDLD1, HDLD2, HDLD3, HDLD4, HDLD5, HDLD6, HDLD7,
            HDLD8, HDLD9, HDGD1, HDGD2, HDGD3, HDGD4, HDGD5, HDGD6, HDGD7, HDGD8, HDGD9, HDFL1, HDFL2, HDFL3, HDFL4,
            HDFL5, HDFL6, HDFL7, HDFL8, HDFL9;

    Text[][] HD = { { HDF1, HDF2, HDF3, HDF4, HDF5, HDF6, HDF7, HDF8, HDF9 },
            { HDHH1, HDHH2, HDHH3, HDHH4, HDHH5, HDHH6, HDHH7, HDHH8, HDHH9 },
            { HDRH1, HDRH2, HDRH3, HDRH4, HDRH5, HDRH6, HDRH7, HDRH8, HDRH9 },
            { HDWH1, HDWH2, HDWH3, HDWH4, HDWH5, HDWH6, HDWH7, HDWH8, HDWH9 },
            { HDSS1, HDSS2, HDSS3, HDSS4, HDSS5, HDSS6, HDSS7, HDSS8, HDSS9 },
            { HDS1, HDS2, HDS3, HDS4, HDS5, HDS6, HDS7, HDS8, HDS9 },
            { HDW1, HDW2, HDW3, HDW4, HDW5, HDW6, HDW7, HDW8, HDW9 },
            { HDHBP1, HDHBP2, HDHBP3, HDHBP4, HDHBP5, HDHBP6, HDHBP7, HDHBP8, HDHBP9 },
            { HDLD1, HDLD2, HDLD3, HDLD4, HDLD5, HDLD6, HDLD7, HDLD8, HDLD9 },
            { HDGD1, HDGD2, HDGD3, HDGD4, HDGD5, HDGD6, HDGD7, HDGD8, HDGD9 },
            { HDFL1, HDFL2, HDFL3, HDFL4, HDFL5, HDFL6, HDFL7, HDFL8, HDFL9 } };
    /* Cumulative-Bottom */
    @FXML
    Text CF1, CF2, CF3, CF4, CF5, CF6, CF7, CF8, CF9, CF10;
    Text[] CF = { CF1, CF2, CF3, CF4, CF5, CF6, CF7, CF8, CF9, CF10 };
    // the array array array
    Text[][][] mag = { NP, CT, PT, PL,HD,};

    protected void cleardata() {// not finished
        for (Text text : CF) {
            //text.setText("void");
        }
        for (Text[][] txtuu : mag) {
            for (Text[] txtu : txtuu) {
                for (Text txt : txtu) {
                    //txt.setText("void");
                }
            }
        }
    }

    protected void displaydata() {
        realdisplay();
    }

    public void DataAdd(ActionEvent actionevent) {
        gotoinput();
    }

    public void gotoabout(ActionEvent actionevent) {
        gotoabout();
    }

    public void Refresh(ActionEvent actionevent) {
        open(ListOTeam.getValue());
        debug();
        displaydata(); 
    }

    public void initialize(URL arg0, ResourceBundle arg1) {
        stage.setOnCloseRequest(e -> closesafe());
        loadteamname();
        addTeamListtobox(ListOTeam);
        cleardata(); 

    }

    private void realdisplay(){
        System.out.println("Here:");
        debug();
//I removed the calculations area because it exceeded the 30000 character limit in Stack overflow
    }

}

I removed the calculations because they take up a ton of space and they don't edit the hashmaps in any way.

I have a few idea to what might be causing the probelem, but trying to change any of those things only made the problem worse.

just an FYI, this program has to do with baseball calculations.

Any ideas are helpful. Thank you in advance.

Upvotes: 0

Views: 69

Answers (1)

Anonymous
Anonymous

Reputation: 86323

In class Data you are initializing each HashMap (Balls, Strikes, etc.) to an empty hash map and then initializing arr to be an array of the HashMaps. In the open method I think that this line is where you are loading the array of hash maps from the serialized file:

    arr = (HashMap[]) ois.readObject();

The line discards the old array that arr was referring to, replacing it with an array of the maps from the file. It does not alter the instance variables Balls, Strikes, etc. They still refer to the empty maps you created first. If you want them to refer to the loaded maps, you need to copy the references the opposite way than you did before:

    Balls = arr[0];
    Strikes = arr[1];

Et cetera.

Upvotes: 2

Related Questions