I'm trying to read the contents of a text file into a list view. The text file is in the format
Item 1
Subitem1 | Subitem2 | Subitem3
Item 2
Subitem1 | Subitem 2 | Subitem3
Item 3
Subitem1 | Subitem2 | Subitem3
This is the logic I used. Search file for specific item
while(scanner.hasNextLine())
{
line=scanner.next line();
if(query.equals(line))
line = scanner.next line();
}
return line;
Take the returned line value and split it into String []
String[] myArray = returnedLine.split("|");
Convert this into List for the list view
List<String> disp = new ArrayList<String>();
disp = Arrays.as list(myArray);
The code works. However, the contents of the list view looks weird, with each alphabet in a new listView row. S on one row, u one the next, followed by b, I, t, e, m and 1. All on separate rows
break;instead of the secondline = scanner.nextLine();in your while loop.NoSuchElementExceptionas you're callingscanner.nextLine()without checkingscanner.hasNextLine()for the second call toscanner.nextLine()