I have a problem with an Android SQLite Database Example with the following code in MainActivity that fails to build;
"error: cannot find symbol method getTitle()"
// get all books
list = db.getAllBooks();
List listTitle = new ArrayList();
for (int i = 0; i < list.size(); i++) {
listTitle.add(i, list.get(i).getTitle());
}
The getAllBooks() query works fine, however the code is meant to extract the title of a book from the LinkedList() named list that was populated by the query. If I drop off the getTitle() like this...
// get all books
list = db.getAllBooks();
List listTitle = new ArrayList();
for (int i = 0; i < list.size(); i++) {
listTitle.add(i, list.get(i));
}
I get data returned as expected in the new ArrayList() named listTitle
Book [id=1, title=The Great Gatsby, author=F. Scott Fitzgerald]
Book [id=2, title=Load of rubbish, author=A. Nonymouse]
Book [id=3, title=A lot more rubbish, author=A.Nonymouse]
Book [id=4, title=Anna Karenina, author=Leo Tolstoy]
Book [id=5, title=The Grapes of Wrath, author=John Steinbeck]
Book [id=6, title=Invisible Man, author=Ralph Ellison]
Book [id=7, title=Gone with the Wind, author=Margaret Mitchell]
Book [id=8, title=Pride and Prejudice, author=Jane Austen]
Book [id=9, title=Sense and Sensibility, author=Jane Austen]
Book [id=10, title=Mansfield Park, author=Jane Austen]
Book [id=11, title=The Color Purple, author=Alice Walker]
Book [id=12, title=The Temple of My Familiar, author=Alice Walker]
Book [id=13, title=The waves, author=Virginia Woolf]
Book [id=14, title=Mrs Dalloway, author=Virginia Woolf]
Book [id=15, title=War and Peace, author=Leo Tolstoy]
Of course, I was just wanting the title in the new list to display on the device, so the issue is how do I access the individual id or title or author from the LinkList() returned by the query..?
Aucun commentaire:
Enregistrer un commentaire