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 trialchloenazaruk
7,091 PointsJava 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
7,091 PointsHi 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
Treehouse Teacherpost.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?
Craig Dennis
Treehouse TeacherCraig Dennis
Treehouse TeacherYay! Great job sticking with it!