title: Exception in thread "Thread-***" java.lang.NullPointerException
body: <p>I have a class to read a text file and put everything in an array. Following is the code I wrote and it ias working fine:</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  
  public class PSResidualReduction {
  
  public PSResidualReduction() throws FileNotFoundException, IOException {
  
  
  
      BufferedReader match_dataset1 = new BufferedReader(new FileReader("/home/mt.txt"));
  
      String[] temp;
      String delims = ",";
  
      double[][] mt;
      mt = new double[10][5];
      for (int k1 = 0; k1 &lt; 10; k1++) {
          String line1 = match_dataset1.readLine();
          temp = line1.split(delims);
          for (int k2 = 0; k2 &lt; 5; k2++) {
              mt[k1][k2] = Double.parseDouble(temp[k2]);
          }
      }
      match_dataset1.close();
  }
  }
  </code></pre>
  
  <p>Since the number of files to read is huge, I decided to use threads to make it faster. Here is the code after using threads:</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  
  public class PSResidualReduction1 implements Runnable {
  
  @Override
  public void run() {
  
      BufferedReader match_dataset1;
      try {
          match_dataset1 = new BufferedReader(new FileReader("/home/mt.txt"));
  
          String[] temp;
          String delims = ",";
  
  
          double[][] mt;
          mt = new double[10][5];
          for (int k1 = 0; k1 &lt; 10; k1++) {
              String line1 = match_dataset1.readLine();
              temp = line1.split(delims);
              for (int k2 = 0; k2 &lt; 5; k2++) {
                  mt[k1][k2] = Double.parseDouble(temp[k2]);
              }
          }
          match_dataset1.close();
      } catch (FileNotFoundException ex) {
          Logger.getLogger(PSResidualReduction1.class.getName()).log(Level.SEVERE, null, ex);
      } catch (IOException ex) {
          Logger.getLogger(PSResidualReduction1.class.getName()).log(Level.SEVERE, null, ex);
      }
  }
  }
  </code></pre>
  
  <p>and I got these errors:</p>
  
  <pre><code>Exception in thread "Thread-***" java.lang.NullPointerException
  </code></pre>
  
  <p>in some of the iterations. The error is from this line </p>
  
  <pre><code>temp = line1.split(delims);    
  </code></pre>
  
  <p>I'm sure all input text files have the same format with the same number of columns and rows.
  P.S. I'm using netbeans.</p>