Note that there are some explanatory texts on larger screens.

plurals
  1. POReading CSV file without third-party libraries
    primarykey
    data
    text
    <p>I'm trying to read a csv file into either an ArrayList or a String [][] array. In this I'm trying to read it into a list and then form the list, using a tokenizer, into an array. The csv file have 7 columns (A - G) and 961 rows (1-961). My for loop for the 2D array keeps returning a null pointer, but I think it should be working..</p> <pre><code>public class FoodFacts { private static BufferedReader textIn; private static BufferedReader foodFacts; static int numberOfLines = 0; static String [][] foodArray; public static String aFact; static int NUM_COL = 7; static int NUM_ROW = 961; // Make a random number to pull a line static Random r = new Random(); public static void main(String[] args) { try { textIn = new BufferedReader(new InputStreamReader(System.in)); foodFacts= new BufferedReader(new FileReader("foodfacts.csv")); Scanner factFile = new Scanner(foodFacts); List&lt;String&gt; facts = new ArrayList&lt;String&gt;(); String fact; System.out.println("Please type in the food you wish to know about."); String request = textIn.readLine(); while ( factFile.hasNextLine()){ fact = factFile.nextLine(); StringTokenizer st2 = new StringTokenizer(fact, ","); //facts.add(fact); numberOfLines++; while (st2.hasMoreElements()){ for ( int j = 0; j &lt; NUM_COL ; j++) { for (int i = 0; i &lt; NUM_ROW ; i++){ foodArray [j][i]= st2.nextToken(); //NULL POINTER HERE System.out.println(foodArray[j][i]); } } } } } catch (IOException e) { System.out.println ("Error, problem reading text file!"); e.printStackTrace(); } } } </code></pre>
    singulars
    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.
 

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