Jump to content

Problem in iterating map

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
hello everybody, there is a method which iterates trough map and returns string represantation of it. I get following errors:

public String getMatchInfo(int scheduleSize)
    {[INDENT]         if (matchMap.size() == 0)
        {[INDENT]             return "Schedule of stadium " + stadiumName + " is empty";
[/INDENT]}
        else
        {[INDENT]             String schedule = "Schedule of stadium " + stadiumName + ":\n";
            Iterator it = matchMap.entrySet().iterator();

            switch (scheduleSize)
            {[INDENT]                 case 0:
                    while (it.hasNext())
                    {[INDENT]                         HashMap.Entry<Integer, Match> pairs = (HashMap.Entry<Integer, Match>)it.next(); //error there: The type HashMap.Entry is 
     //not visible
                        schedule += (pairs.getValue()).getPreMatchInfo();
                        schedule += "\n";
[/INDENT]}
                default:
                    int i = 0;

                    while (it.hasNext())
                    {[INDENT]                                   i++;
          if (i > matchMap.size())[INDENT]          break;
[/INDENT]HashMap.Entry<Integer, Match> pairs = (HashMap.Entry<Integer, Match>)it.next(); // Error there: The type HashMap.Entry is 
     //not visible
                        schedule += (pairs.getValue()).getPreMatchInfo();
                        schedule += "\n";
[/INDENT]}
[/INDENT]}
return schedule;
[/INDENT]}
[/INDENT]}

HashMap is imported

Edited by ZekeDragon, 17 October 2010 - 03:04 AM.
Please use [code] tags when posting code.


#2
eman ahmed

eman ahmed

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
please , can you post the full source with clear signature ? I think if you do it, I will able to help you

#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
What does the 'matchMap' contain? What are the data types of the key and value?

Also the type is not visible may indicate that you're missing an import statement. Assuming the code is correct this import statement may look like:
import packagename.Match;

#4
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Try using Map.Entry instead of HashMap.Entry. While HashMap does implement the Map interface, that probably doesn't mean that HashMap will work to reference Map.Entry. You'll need to import Map to do this as well.
Wow I changed my sig!