我想解決這個錯誤,但由於某種原因,無法找到問題來解決它。我在此代碼中使用Collection
。如果任何人都可以指出我缺少的是什麼,那我會很有幫助的。我使用的集合只能遍歷數組或java.lang.Iterable的實例
Collection challenges = null;
Map challengesMap = new HashMap<String,String>();
ForgotPasswordManager forgotPwdMgr = new ForgotPasswordManager(platform);
System.out.println("after ForgotPasswordManager(platform)...before getSecretQuestion()");
challenges = forgotPwdMgr.getSecretQuestion(userID);
System.out.println("after getSecretQuestion()...");
for (Object challenge : challenges) {
String challengeStr = (String)challenge;
System.out.println("doGetChallenges()...ChallengeStr = " + challengeStr);
challengesMap.put(challengeStr.trim(), "");
}
我在網上收到此錯誤Can only iterate over an array or an instance of java.lang.Iterable
:這裏for (Object challenge : challenges)
[錯誤:只能遍歷數組或java.lang.Iterable的實例](https://stackoverflow.com/questions/22425277/error-can-only-iterate-over-an -array或 - 一個實例-的-java的琅可迭代)。 [第二個答案](https://stackoverflow.com/a/22425341/4660897)解釋了這個問題。 –