简体   繁体   English

我正在使用Collection只能迭代数组或java.lang.Iterable的实例

[英]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.

相关问题 只能迭代一个数组或java.lang.Iterable的实例 - Can only iterate over an array or an instance of java.lang.Iterable 只能迭代java.lang.Iterable的数组或实例吗? - Can only iterate over an array or an instance of java.lang.Iterable? 在包含私有集合的类上使用迭代器错误“只能迭代数组或java.lang.Iterable的实例” - Error “Can only iterate over an array or an instance of java.lang.Iterable” using iterator on a class that contains a private collection 使用FileUtils时只能迭代数组或java.lang.Iterable的实例 - Can only iterate over an array or an instance of java.lang.Iterable while using FileUtils 只能在java.lang.Iterable中的数组或实例上进行迭代 - Can only iterate over an array or an instance of java.lang.Iterable in java Eclipse 编译错误显示不正确(只能迭代数组或 java.lang.Iterable 的实例) - Eclipse compile error shown incorrectly (Can only iterate over an array or an instance of java.lang.Iterable) 错误:只能遍历数组或java.lang.Iterable的实例 - Error: can only iterate over an array or an instance of java.lang.Iterable 另一个“只能迭代数组或java.lang.Iterable的实例”问题 - Yet another “Can only iterate over an array or an instance of java.lang.Iterable” issue 规则编译错误:只能迭代java.lang.Iterable的数组或实例 - Rule Compilation error : Can only iterate over an array or an instance of java.lang.Iterable ForStatement-只能迭代数组或java.lang的实例。在csv文件创建中可迭代 - ForStatement - Can only iterate over an array or an instance of java.lang.Iterable in csv file creation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM