下面的代码给我“ String item:keys”键的错误。据说对象不能转换为字符串。我的助教说,这是因为我没有要遍历的“键”集合-它不存在。这不像Java import.util.Collection,而是通过...迭代的键的集合。我不确定如何创建它。我将在哪里创建它?
public String getLongDescription()
{
String str = "You are " + description + ".\n"; str+= getExitString() + ".\n \n"; str+= "This room contains :\n";
Set keys = itemsInRoom.keySet();
for(String item : keys)
{
str+=item+":";
str+=itemsInRoom.get(item).getItemDescription() + "\n";
}
return str;
}