Friday 30 August 2013

Trouble with adding to HashMap using arguments

Trouble with adding to HashMap using arguments

I am a newbie programmer and I can't figure out what is wrong with my
addServer method. "details" is underlined and wants a semicolon next to it
(I'm using Eclipse). I thought that I had set it up correctly but
obviously I am wrong. It is called from the main and it's purpose is to
add to a hashmap of servers where the value of the hashmap consists of an
instance of ServerDetails where two int fields are stored. All values are
determined in the main. Before, serverList's value was just one integer
and I didn't use an object and I got it to work fine. If I need to show
more code, please let me know.
public class ClientSummary {
private String clientID;
private String companyName;
private int totalNum;
private HashMap<String,ServerDetails> serverList;
public ClientSummary (){
clientID = MainDisplay.getClientHolder();
totalNum= MainDisplay.getNumAttackOnClient();
serverList = new HashMap<String,ServerDetails>();
}
public void addServer(String x, int y, int z){
ServerDetails details new ServerDetails(y,z);
serverList.put(x, details);
}
}
ServerDetails.java:
public class ServerDetails {
private int threatLevel;
private int numAttack;
ServerDetails(int y, int z){
threatLevel = y;
numAttack = z;
}
}

No comments:

Post a Comment