I am still a newb, so please forgive my lack of knowledge. I have tried to save a string (manager name) which is taken as input via the scanner class. This works, I have also serialized the string, however when I de-serialize the string, the memory address is displayed, rather than the manager name.
How can I display the manager name, and from a learning point of view, why is my saved string defaulting to a memory address after serialization. Below are some code snippets, (Please don't mention try with resources, I am learning and will do this eventually!) thanks in advance :)
import java.util.InputMismatchException;
import java.util.Scanner;
import java.io.*;
import java.util.Arrays;
public class ReadClub{
public void tryReadClub(ClubInfo club, MainMenu getFullName){
String fileName = "/home/cg/root/savedgames/" + club.clubID + " " + club.teamName;
try
{
FileInputStream fileIn = new FileInputStream("" + fileName + ".ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
club = (ClubInfo) in.readObject();
getFullName = (MainMenu) in.readObject();
in.close();
fileIn.close();
}catch(IOException i)
{
// i.printStackTrace();
System.out.println("Not a valid number");
return;
}catch(ClassNotFoundException c)
{
System.out.println("Club class not found");
c.printStackTrace();
return;
}
System.out.println("Saved game loaded...");
System.out.println("Name: " + club.teamName);
System.out.println("Stadium: " + club.stadium);
System.out.println("Division: " + club.division);
// System.out.println("SSN: " + club.SSN);
System.out.println("Stadium Capacity: " + club.stadiumCapacity);
System.out.println("Manager Name :" + getFullName);
}
}
public class DeSerializer extends ReadClub
{
public void DeSerialize(ClubInfo club){
MainMenu pass_choice2 = new MainMenu();
int passed_choice = pass_choice2.savedTeamList(club);
MainMenu getFullName = new MainMenu();
if(passed_choice==1){tryReadClub(club, getFullName);}
}
--------------------------------------------------------------------------------
// This method is held in my MainMenu class
public String createProfile(){
System.out.println("Please enter your first name: ");
Scanner in = new Scanner(System.in);
System.out.println("\n");
String firstName = in.nextLine();
System.out.println("Please enter your surname: ");
String surname = in.nextLine();
String fullName = firstName + surname;
System.out.println("Your full name is:" + fullName);
return fullName;
} // end createProfile