Note that there are some explanatory texts on larger screens.

plurals
  1. POCode keeps printing null
    primarykey
    data
    text
    <p>This code is supposed to read one text file of multiple grocery lists and then split them up into an arraylist of separate grocery lists. Then it should split each element of the arraylist (each individual grocery list) into a new arraylist by line. So it's almost like an array list within an arraylist. Does this code work for that? When I try to get the array using the getArray method in my main method and then I print the array but it keeps printing null. What's up?</p> <pre><code>public class Grocery { Scanner input; String groceryLine; String line; ArrayList&lt;String&gt; grocery = new ArrayList&lt;String&gt;(); String groceryString; //ArrayList&lt;String&gt; newString = new ArrayList&lt;String&gt;(); String store; String brand; String serialNumber; String[] newString; public Grocery() throws IOException{ File inFile = new File ("groceryList.txt"); input = new Scanner (inFile); String grocery; while (input.hasNext()) { grocery = input.nextLine(); } } public void makeLists() { while(input.hasNextLine()) { line = input.nextLine(); if(line.equals("-finish-")){ grocery.add(groceryLine); } else { groceryLine = groceryLine + "\n" + line; } } } public String[] getArray() { for(int i=0; i&lt;grocery.size(); i++) { groceryString = grocery.get(i); newString =groceryString.split("\n"); //store = newString[1]; //brand = newString[4]; //serialNumber = newString[5]; } return newString; } } </code></pre> <p>groceryList.txt looks something like: -Start- Store: SuperSupermarket Address: 23 Rose Road Brand: Superfoods Serial Number: 36575 Items: Bread Milk Cheese Ham Soup -finish-(indicates the end of one list) -start-(start a new list like the first one but different store and stuff)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload