title: How to stop a NullPointerException when using BufferedReader (readLine()) to check for any more values
body: <p>I have written some code to read in Vehicle data from a .txt file. At the moment I can read in all the data correctly and create the objects fine. I have a while loop that checks for the text "Vehicle Details" in the file and if it is present (i.e. there is another vehicle to add) it enters the loop to add the data.</p>
  
  <p>The problem is that when there isn't anymore data the readLine() method is still called and this creates a NullPointerException (at least that's what I think is the cause)</p>
  
  <p>Here is the method in use.</p>
  
  <pre><code>public static void addNewVehicleFromFile(Showroom s)
  {
      try
      {
          FileInputStream fStream = new FileInputStream("AddVehicleFromFile.txt");
          BufferedReader br = new BufferedReader(new InputStreamReader(fStream));
          String stringLine;
  
          while ((stringLine = br.readLine()).equalsIgnoreCase("Vehicle Details"))
          {
              System.out.println("P1");//Testing
              br.readLine();
  
              String[] manufacturer = br.readLine().split(" =");
              String[] model = br.readLine().split(" =");
              String[] vin = br.readLine().split(" =");
              String[] dateOfMan = br.readLine().split(" =");
              String[] taxBand = br.readLine().split(" =");
              String[] cost = br.readLine().split(" =");
  
              System.out.println("P2");//Testing
              System.out.println(manufacturer[0].toString());
              System.out.println(model[0].toString());
              System.out.println(vin[0].toString());
              System.out.println(dateOfMan[0].toString());
              System.out.println(taxBand[0].toString());
  
              br.readLine();
  
              System.out.println("P3");//Testing
  
              int strToInt = Integer.parseInt(cost[0]);
  
              Vehicle inputVehicle = new Vehicle(manufacturer[0], model[0], vin[0], dateOfMan[0],
                      taxBand[0].charAt(0), strToInt);
  
              System.out.println("P4");//Testing
  
              s.addVehicle(inputVehicle);
  
              System.out.println("P5");//Testing
          }
  
      }
      catch (FileNotFoundException fnfe)
      {
          System.out.println("File not found exception: " + fnfe.toString());
      }
      catch (IOException ioe)
      {
          System.out.println("I/O exception: " + ioe.toString());
      }
  
      System.out.println("addNewVehicleFromFile Complete");
  
  }
  </code></pre>
  
  <p>Not sure if you need it but here is my file data.</p>
  
  <pre><code>Vehicle Details
  
  Fordtest =manufacturer
  Focus =model
  ioCheck =VIN
  09/01/1989 =DateOfMan
  d =TaxBand
  19900 =Cost
  
  Vehicle Details
  
  Fordtest2 =manufacturer
  Focus2 =model
  ioCheckVIN2 =VIN
  09/01/1989 =DateOfMan
  a =TaxBand
  1922 =Cost
  </code></pre>
  
  <p>Finally, to make it clear where the program runs to I have added in some console output as testing. The while loops iterates twice outputting p1-p5 both times before the error occurs and it never reaches the final console output saying the method is complete.</p>