java.lang.Iterable错误-这是什么意思,我该如何解决? [英] java.lang.Iterable error - What does this mean and how do I fix it?

查看:104
本文介绍了java.lang.Iterable错误-这是什么意思,我该如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天来我一直在寻找答案,但是没有运气.已经很晚了,我很累,所以我想把它放在这里,并希望有人可以提供帮助.这是我的代码片段,它们在Eclipse中弹出错误.

I've been trying to find an answer to this for a couple days now and have had no luck. It is very late and I am very tired so I thought I would put it up here and hope that someone out there can help. Here is my snippit of code that is popping an error in Eclipse.

private void filterByTitle() {
    String title = Validator.getLine(sc, "Enter the Title to retrieve: ");
    System.out.println("\n" + Book.getHeadings());
    for(Book book : bookList.filterListByTitle(title)) {
        System.out.println(book);
    }   
}

出现错误的部分是:bookList.filterListByTitle(title))".错误为只能迭代java.lang.Iterable的数组或实例".

The part with the error is " : bookList.filterListByTitle(title))". The error is "Can only iterate over an array or an instance of java.lang.Iterable".

我是Java的新手,所以请不要只重复错误.我知道有错误,但我不知道这意味着什么或如何解决.如果可以的话请帮忙.

I am new to Java, so please don't just repeat the error. I know there is an error, but I don't know what it means or how to fix it. Please help if you can.

谢谢.

推荐答案

bookList.filterListByTitle()需要返回一个实现java.lang.Iterable的对象,或者它必须是一个数组.在那种情况下,无论返回什么,都应该实现Iterable的必要方法,或者扩展一个抽象子类(如AbstractList),或者将其扩展为数组.

bookList.filterListByTitle() needs to return an object that implements java.lang.Iterable or it needs to be an array. In that case, whatever it returns should implement the necessary method for Iterable or extend one of the abstract subclasses like AbstractList, OR be an array.

这篇关于java.lang.Iterable错误-这是什么意思,我该如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆