title: NullPointerException while reading from a file
body: <p>I encounter a java.lang.NullPointerException error when running my Java program, and after reading up on it I think I understand what the error means, but I'm still not sure how to fix it.</p>
  
  <pre><code>import java.util.ArrayList;
  import java.io.FileInputStream;
  import java.io.DataInputStream;
  import java.io.BufferedReader;
  import java.io.FileOutputStream;
  import java.io.InputStreamReader;
  import java.io.IOException;
  import java.io.PrintStream;
  public class readFile {
  
  
  public static ArrayList&lt;String&gt; pullFirst(String fileName) throws IOException{
      String filen = "C:\\Users\\Steven\\Desktop\\Tests\\wunderground\\outputTweetsWeather.txt";
      ArrayList&lt;String&gt; arl = new ArrayList&lt;String&gt;(); // java 6 ArrayList 
  
      FileInputStream fs = new FileInputStream(filen); // this is how you access a file in java
      DataInputStream din = new DataInputStream(fs);
      BufferedReader bin = new BufferedReader(new InputStreamReader(din));
  
      String line;    
      while(!(line = bin.readLine()).startsWith("String index out of range")){ // read each line in the file while they exist
          arl.add(line);                // add them to the array list
      }
  
      return arl;                                  // return the array list
  }
  
  public static void main(String[] args, int j) {
  
      // this is just demo code to prove it works so you can check the output.
      try{
      ArrayList&lt;String&gt; rVal = pullFirst("testFile.txt");
          for(String a : rVal){
              //System.out.println(a + "\n"); // insert write to file code here
             if(a.startsWith("+t")){
         //          System.out.println(a);
             }
          }
          int i = 36;
  
  
          PrintStream out5 = new PrintStream(new FileOutputStream("forpopUp1.txt", true));
  
          System.setOut(out5);
       System.out.println(rVal.get(2 + j*i)); // Display Value
  
  
      }catch(Exception e){
          System.out.print("Problem in readFile" + e);
      }
  
  }
  }
  </code></pre>
  
  <p>Now I'm not sure if it's to do with the fact that my main line is </p>
  
  <pre><code>public static void main(String[] args, int j) {
  </code></pre>
  
  <p>But, as far as I'm aware I have to have it this way, as this class is executed after an if condition from another class is ran, using the line</p>
  
  <pre><code>readFile.main(args, counterForreadFile);
  </code></pre>
  
  <p>This is the result of the StackTrace:</p>
  
  <pre><code>java.lang.NullPointerException
  at readFile.pullFirst(readFile.java:22)
  at readFile.main(readFile.java:33)
  </code></pre>
  
  <p>Any help would be appreciated!</p>