title: Searching a Text File and Returning array in Java
body: <p>My project for programming class is to create a program (using NetBeans) where users may enter Movie Information and store it. They are able to Search the list of movies for information, ie title, actor, quality etc. I have a java file that allows users to enter information about the movie in textfields and it saves it to a txt file. </p>
  
  <p>The problem I am having is that everytime the user searches for the movie, it returns a null pointer exception.</p>
  
  <p>Here is the part of my code for searching:</p>
  
  <pre><code>private void sbtnActionPerformed(java.awt.event.ActionEvent evt) {                                     
      try{
          if(!mField.getText().equals("Search Movie Title")){
              if(sameTitle(mField.getText())!=null){
                  display_Search_Info.main(info);
                  dispose();
              }else{
                  JOptionPane.showMessageDialog(null, "No Movie Info Found.", "Error", JOptionPane.WARNING_MESSAGE);
              }
          }
          if(!aField.getText().equals("Search Actor Name")){
              if(sameActor(aField.getText())!=null){
                  display_Search_Info.main(info);
                  dispose();
              }else{
                  JOptionPane.showMessageDialog(null, "No Movie Info Found.", "Error", JOptionPane.WARNING_MESSAGE);
              }
          }
          if(!gBox.getSelectedItem().equals("Select Genre")){
              if(sameGenre(String.valueOf(gBox.getSelectedItem()))!=null){
                  display_Search_Info.main(info);
                  dispose();
              }else{
                  JOptionPane.showMessageDialog(null, "No Movie Info Found.", "Error", JOptionPane.WARNING_MESSAGE);
              }
          }
          if(!lBox.getSelectedItem().equals("Select Location")){
              if(sameLocation(String.valueOf(lBox.getSelectedItem()))!=null){
                  display_Search_Info.main(info);
                  dispose();
              }else{
                  JOptionPane.showMessageDialog(null, "No Movie Info Found.", "Error", JOptionPane.WARNING_MESSAGE);
              }
          }
          if(mField.getText().equals("Search Movie Title")&amp;&amp;aField.getText().equals("Search Actor Name")&amp;&amp;gBox.getSelectedItem().equals("Select Genre")&amp;&amp;lBox.getSelectedItem().equals("Select Location")){
              JOptionPane.showMessageDialog(null, "Please Enter Information About The Movie", "Error", JOptionPane.WARNING_MESSAGE);                
          }
      }catch(IOException e){
          System.out.println("Error Occured");
      }    
  }                                    
  public String[] sameTitle(String s) throws IOException{
      BufferedReader br=new BufferedReader(new FileReader("M:/NetBeans Projects/MovieList/src/MovieInfo.txt"));
      String line;
      info= new String[6];
      do{
          for(int i=0; i&lt;6; i++){
              info[i]=br.readLine();
          }
      }while((line=br.readLine())!=null);
  
      if(info[0].contains(s)){
          return info;
      }else{
          return null;
      }
  
  }
  public String[] sameActor(String s) throws IOException{
      BufferedReader br=new BufferedReader(new FileReader("M:/NetBeans Projects/MovieList/src/MovieInfo.txt"));
      String line="";
      info= new String[6];
      while((line=br.readLine())!=null&amp;&amp;!info[1].contains(s)||!info[2].contains(s)){
          for(int i=0; i&lt;6; i++){
              info[i]=br.readLine();
          }
      }
      if(info[1].contains(s)||info[2].contains(s)){
          return info;
      }else{
          return null;
      }
  }
  public String[] sameGenre (String s) throws IOException{
      BufferedReader br=new BufferedReader(new FileReader("M:/NetBeans Projects/MovieList/src/MovieInfo.txt"));
      String line="";
      info= new String[6];
      while((line=br.readLine())!=null&amp;&amp;!info[3].contains(s)){
          for(int i=0; i&lt;6; i++){
              info[i]=br.readLine();
          }
      }
      if(info[3].contains(s)){
          return info;
      }else{
          return null;
      }
  }
  public String[] sameLocation (String s) throws IOException{
      BufferedReader br=new BufferedReader(new FileReader("M:/NetBeans Projects/MovieList/src/MovieInfo.txt"));
      String line="";
      info= new String[6];
      while((line=br.readLine())!=null&amp;&amp;!info[4].contains(s)){
          for(int i=0; i&lt;6; i++){
              info[i]=br.readLine();
          }
      }
      if(info[4].contains(s)){
          return info;
      }else{
          return null;
      }
  }
  </code></pre>
  
  <p>The jOptionPane does not work and it does not send it to the next file just simply getting
  "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException".</p>