[英]i am using Collection Can only iterate over an array or an instance of java.lang.Iterable
I am trying to solve this error, but for some reason, not able to find the issue to fix it. 我正在尝试解决此错误,但是由于某种原因,无法找到要解决的问题。 I am using
Collection
in this code. 我在这段代码中使用
Collection
。 If anyone can point me out what actually I am missing, I would be a great help. 如果有人可以指出我实际上所缺少的内容,那将对我有很大的帮助。
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(), "");
}
I am getting this error Can only iterate over an array or an instance of java.lang.Iterable
on line: for (Object challenge : challenges)
我收到此错误
Can only iterate over an array or an instance of java.lang.Iterable
:on for (Object challenge : challenges)
The Collection
type referenced here : 这里引用的
Collection
类型:
Collection challenges = null;
is not the java.util.Collection
interface that extends the Iterable
interface. 是不是
java.util.Collection
扩展接口Iterable
接口。
Otherwise you would have not this error message : 否则,您将不会收到此错误消息:
Can only iterate over an array or an instance of java.lang.Iterable
只能迭代一个数组或java.lang.Iterable的实例
at this line : 在这一行:
for (Object challenge : challenges) {
You are using probably a custom Collection
class. 您可能正在使用自定义
Collection
类。
So to solve your problem, make your custom custom Collection
class implement Iterable
or more simple : use JDK java.util.Collection
subclasses. 因此,要解决您的问题,请使您的自定义自定义
Collection
类实现Iterable
或更简单:使用JDK java.util.Collection
子类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.