title: Dealing with txt file via split(), says Nullpointerexception
body: <p>I know there are many similar questions here, but I still can't solve it. I can get all the results that I want. However, in the end, it still shows <code>nullpointerexception</code>. I don't know why. can anyone help?</p>
  
  <pre><code>public class PointGenterate {
  
  public static void main(String[] args) throws FileNotFoundException {
      // TODO Auto-generated method stub
      try{
      File file = new File("123.txt");
      double[] pointsid = new double[10];
      String[] data = null;
  
      for(int i = 0; i &lt;10; i++){
          double rn = (int)(Math.random()*120);
          System.out.println(rn);
          pointsid[i] = rn;
      }
      //read file
      InputStreamReader rs = new InputStreamReader(new FileInputStream(file));//create input stream reader object
      BufferedReader br = new BufferedReader(rs);
      String line = "";
      line = br.readLine();
      //
      File write = new File("output.KML");
      write.createNewFile();
      BufferedWriter out = new BufferedWriter(new FileWriter(write));
      while(line != null){
          line = br.readLine();
          if(line==" "){
              System.out.print("empty");
          }else{
          data = line.split(",|:|[|]");
          }
          for(int i = 0; i &lt; data.length; i++){
              data[i] = data[i].trim();
              System.out.println(data[i] + "num" + i);
          }
          if(data.length &gt; 15){
              double id = Double.parseDouble(data[4]);
              for(int i = 0; i &lt;10; i++){
                  if(id == pointsid[i]){
                      data[10] = data[10].substring(0, data[10].length()-2);
                      data[15] = data[15].substring(1,data[15].length());
                      data[16] = data[16].substring(0, data[16].length()-6);
                      out.write(data[8]+" "+ data[10]+ " " + data[13] + data[15] + data[16]+ "\r\n");
                      out.flush();
                  }
              }
          }
  
  
  
          //System.out.println(line);
      }
  
  
  
      out.close();
      }
      catch(Exception e){
          e.printStackTrace();            
      }
  }
  
  }
  </code></pre>
  
  <p>the txt file format is like </p>
  
  <pre><code>{ "type": "Feature", "properties": { "id": 126.000000, "osm_id": 4851918786.000000, "name": "Moray House Library", "type": "library" }, "geometry": { "type": "Point", "coordinates": [ -3.180841771200988, 55.950622362732418 ] } },
  </code></pre>
  
  <p>this is one line. I have many lines, and actually this is just a test code. if it works. i want to write it as a method in a javaseverlet class. get the string coordinates and return it to my JS font-end. </p>