I have read several articles on how pass-by-value works, but I cannot call my serialized methods from my case statement, because I am not correctly passing my "club" variable. I understand that it outside of the scope of my "MainMenu" class, but I don't know the syntax to pass it to my "MainMenu" class.
I thought about passing it to my "MainMenu" constructor, which I have tried, but I then need to cast the type from object to String, and I am struggling with this.
How do I stop "club" from displaying "cannot find symbol" ? This happens in my Serialize case statements.
Here is my stack trace, I have also included the code snippets which are most pertinent.
MainMenu.java:19: error: cannot find symbol
MainMenu team = new MainMenu(club);
^
symbol: variable club
location: class MainMenu
MainMenu.java:49: error: cannot find symbol
saveclub1.Serialize(club , club_one);
^
symbol: variable club
location: class MainMenu
MainMenu.java:49: error: cannot find symbol
saveclub1.Serialize(club , club_one);
^
symbol: variable club_one
location: class MainMenu
MainMenu.java:72: error: cannot find symbol
saveclub2.Serialize(club , club_one);
^
symbol: variable club
location: class MainMenu
MainMenu.java:72: error: cannot find symbol
saveclub2.Serialize(club , club_one);
symbol: variable club_one
location: class MainMenu
5 errors
MainMenu.java snippet
String[] clubName = {"Arsenal","Aston Villa", "Bournemouth", "Chelsea", "Crystal Palace", "Everton", "Leicester City", "Liverpool", "Manchester United", "Manchester City", "Newcastle United", "Norwich City", "Southampton", "Stoke City", "Sunderland", "Swansea City", "Tottenham Hotspur", "Watford", "West Brom", "West Ham United"};
String[] Menu = {"Choose Team", "Create Profile","Load Game", "Credits" , "Quit" , "Save Game" , "League Table"};
public MainMenu(ClubInfo club){
// clubName = club; // cast object club, to make it a String e.g clubName?
//constructor
}
public static void main(String args[]){
MainMenu team = new MainMenu(club);
}
More from MainMenu.java
case 2:
Serialize saveclub1 = new Serialize();
saveclub1.Serialize(club , club_one);
exit = true;
break;
case 6:
Serialize saveclub2 = new Serialize();
saveclub2.Serialize(club , club_one);
exit = true;
break;
Serialize.java
import java.util.InputMismatchException;
import java.util.Scanner;
import java.io.*;
import java.util.Arrays;
public class Serialize
{
public Serialize(){
//constructor
}
public void Serialize(ClubInfo club , Club1 club_one) // receive return type from printGreeting();
{
String fileName = club.teamName + ".ser";
try {
FileOutputStream fileOut = new FileOutputStream("/home/cg/root/" + fileName);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(club);
out.close();
fileOut.close();
System.out.printf("Serialized data is saved in C:/tmp/club.ser");
}catch(IOException i)
{
i.printStackTrace();
}
}
}
import java.util.InputMismatchException;
import java.util.Scanner;
import java.io.*;
import java.util.Arrays;
/**
*
* @author Darren Estcourt
*/
public class ClubInfo implements java.io.Serializable{
public ClubInfo(){
//constructor
}
public String teamName;
public String stadium;
public String division;
public transient int SSN;
public int stadiumCapacity;
} // end ClubInfo class
-------------------------------------------------------------------------------
public class Club1{
public Club1(){
//constructor
}
public void club_one(ClubInfo club){
club.teamName = "Arsenal";
club.stadium = "Emirates";
club.division = "Premier League";
club.SSN = 11122333;
club.stadiumCapacity = 60000;
}
}
In short, how can I ensure "club" and "club_one" are recognised by my "MainMenu" class. Previously I have been relying on inheritence to pass values, but I have read that constructors and objects are what I might be looking for.
I am very much a newb, any help is greatly appreciated :)