Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAyushman Khazanchi
14,915 PointsMap.Entry results in 'incompatible types' error
Followed the code in the Designing the UI video but getting this error on the for-each loop, specifically on this - Map.Entry<String, String> option
Error:(28, 62) java: incompatible types: java.lang.Object cannot be converted to java.util.Map.Entry<java.lang.String,java.lang.String>
private String promptAction() throws IOException {
System.out.printf("There are %d songs available. Your options are: %n", mSongBook.getSongCount());
for(Map.Entry<String, String> option : mMenu.entrySet()) {
System.out.printf("%s - %s %n", option.getKey(), option.getValue());
}
System.out.printf("What do you want to do? %n");
String choice = mReader.readLine();
return choice.trim().toLowerCase(); // trim removes whitespace at beginning and end of String
}
1 Answer
Ayushman Khazanchi
14,915 PointsNevermind, I figured it out. Here's what was missing (in case anyone runs into this) -
My definition of mMenu was incorrect -
private Map mMenu;
and I fixed the issue by changing it to this -
private Map<String, String> mMenu;