Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Ayushman Khazanchi
Ayushman Khazanchi
14,915 Points

Map.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
Ayushman Khazanchi
14,915 Points

Nevermind, 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;