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.

Java Java Data Structures Exploring the Java Collection Framework Maps

chloenazaruk
chloenazaruk
7,091 Points

Java Maps coding challenge expression type error message

I'm trying to run this code for the maps challenge, but keep getting this error message. Can anyone point me in the right direction?

Thanks!!

Chloe

./com/example/Blog.java:32: error: for-each not applicable to expression type for (String category : post.getCategory()) { ^ required: array or java.lang.Iterable found: String Note: JavaTester.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error

2 Answers

chloenazaruk
chloenazaruk
7,091 Points

Hi Craig,

Thank you so much for the help- I eventually got unstuck on it and got there.

Thanks for the great training! It's so helpful and I'm learning loads.

Craig Dennis
Craig Dennis
Treehouse Teacher

Yay! Great job sticking with it!

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

post.getCategory returns a String which is the category. I think you want to loop over the posts and use each post's category as the key in a new map.

Does that help get you unstuck?