title: NullPointerException, java.util.StringTokenizer.<init>(Unknown Source)
body: <p>this program is to add data about product in a text file, If same product is given second time ,I am getting an exception called </p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at java.util.StringTokenizer.&lt;init&gt;(Unknown Source)
      at java.util.StringTokenizer.&lt;init&gt;(Unknown Source)
      at ECME.Products.newProd(Products.java:86)
      at ECME.Products.main(Products.java:25)
  </code></pre>
  
  <p>everytime when i adding data of same mobile system should generate new id's.
       Please anyone help me. Regards</p>
  
  <pre><code>package ECME;
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.File;
  import java.io.FileReader;
  import java.io.FileWriter;
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Scanner;
  import java.util.StringTokenizer;
  
  public class Products implements Product {
      static Scanner sc = new Scanner(System.in);
      public static void main(String[] args) {
  
  
  
          System.out.println("1. Add New Products");
          System.out.println("2. Check Existing Products");
          System.out.println("Please enter your option");
          Products pro = new Products();
          int pOption = sc.nextInt(); 
          switch (pOption) {
          case 1: pro.newProd();
  
          break;
  
          case 2:pro.existingProd();
  
          break;
  
          default:
              break;
          }
      }
  
      private int pflag;
  
      @Override
      public void newProd() {
          System.out.println("Adding Information about new product");
          System.out.println("Enter the product type");
          String pType= sc.next();
          System.out.println("Enter the name of the product");
          String pName= sc.next();
          System.out.println("Enter the cost of the product");
          int pCost = sc.nextInt();
          System.out.println("Enter the number of products you want to add");
          int pQuantity = sc.nextInt();
          int oldPQuantity = pQuantity;
  
          int num=1;
          try {
              for(int i=1;i&lt;=pQuantity;i++)
              {
                  int l=pQuantity;
                  File file = new File("D:/ACME/Products.txt");
  
  
  
                  if (!file.exists()) {
                      file.createNewFile();
                      throw new IOException();
                  }
  
                  FileWriter fileWritter = new FileWriter(file,true);
                  @SuppressWarnings("resource")
                  BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
                  bufferWritter.newLine();
  
  
                  BufferedReader br1 = null;
                  br1 = new BufferedReader(new FileReader("D:/ACME/Products.txt"));
  
                  String entireFileText[]= new String[200];
                  int i1 =0;
                  while((entireFileText[i1]=br1.readLine())!=null)
                  {
  
                      i1++;
                  }   
                  //              System.out.println("----&lt;&lt;&lt;"+i1);       
                  int j=1;
                  StringTokenizer st;
                  for(int o=1;o&lt;i;o++){
                      st = new StringTokenizer(entireFileText[o]);
  
                      String[] im1 = new String[1000];
  
  
                      while(st.hasMoreTokens()){
                          im1[j]= (String) st.nextToken();
  
                          j++;
                      }       
  
  
                      //                  System.out.println("--------&gt;"+j);
                      for(int y=1;y&lt;=300;y++)
                      {
                          if(pName.equals(im1[y]))
                          {   int existingQuantity = Integer.parseInt(im1[y+2]);
                          System.out.println("im1[y+2] is--&gt;"+im1[y+2]);
                          oldPQuantity = existingQuantity;
                          pQuantity+=oldPQuantity;
                          System.out.println("opq-&gt;"+oldPQuantity);
                          System.out.println("pq-&gt;"+pQuantity);
                          pflag=1;
                          break;
  
                          }
                          if(pflag==1)
                              break;
                      }
  
  
  
                      l++;
                      int op=oldPQuantity+l;
                      //              op++;
                      //              l=op+1;
                      String pId = pName+"-"+num+op;
                      String content = pType+"\t"+pId+"\t"+pName+"\t"+pCost+"\t"+pQuantity;
  
                      System.out.println(content);
                      bufferWritter.write(content);
                      bufferWritter.close();
                      br1.close();
                  }
              } 
          }       
          catch (IOException e) {
              e.printStackTrace();
          }
  
      }
  
      public void existingProd() {
          BufferedReader br = null;
  
          try {
  
              String sCurrentLine;
  
              br = new BufferedReader(new FileReader("D:/ACME/Products.txt"));
  
              while ((sCurrentLine = br.readLine()) != null) {
                  System.out.println(sCurrentLine);
              }
  
          } catch (IOException e) {
              e.printStackTrace();
          } finally {
              try {
                  if (br != null)br.close();
              } catch (IOException ex) {
                  ex.printStackTrace();
              }
          }
  
      }
  
  }
  </code></pre>