title: java.util.NoSuchElementException: No line found*
body: <p>I keep getting this error
  <code>java.util.NoSuchElementException</code> No line found
  when I use this method</p>
  
  <pre><code>public boolean hasMoreCommands() {
      if (input.hasNextLine()) {
          return true;
      } else {
          //input.close();
          return false;
      }
  }
  
  public void advance() {
      String str;
      if(hasMoreCommands() == true){
          do {
              str = input.nextLine().trim();
  
              // Strip out any comments
              if (str.contains("//")) {
                  str = (str.substring(0, str.indexOf("//"))).trim();
              }
          } while (str.startsWith("//") || str.isEmpty() || hasMoreCommands());
          command = str;
    }
  }
  </code></pre>
  
  <p>I have main code here:</p>
  
  <pre><code>public class Ptest
  {
    public Ptest(String fileName)
    {
      String line = null;
      String nName = fileName.replace(".vm", ".asm");
      Parser p = new Parser();
  
      try{ 
          File neF = new File(nName);
          if(!neF.exists()){
              neF.createNewFile();
          }
          File tempFile = new File("temp.txt");
          if(!tempFile.exists()){
              tempFile.createNewFile();
          }
  
          FileReader fr = new FileReader(fileName);
          BufferedReader br = new BufferedReader(fr);
          FileWriter fw = new FileWriter(nName);
          BufferedWriter bw = new BufferedWriter(fw);
          FileWriter writR = new FileWriter(tempFile);
          BufferedWriter buffR = new BufferedWriter(writR);
          while((line = br.readLine()) != null) {
              buffR.write(line+ "\n");
              //System.out.println(line);
          }  
          buffR.flush();
          buffR.close();
          p.insertTitle(tempFile);
          String ctype = p.commandType();
          int len = ctype.length();
          int spaces = 13 - len;
          String sp = " ";
          String asp = " ";
          String a1 = null;
          int a2;
          int alen;
          boolean t = false;
          while(p.hasMoreCommands()){
              for(int i= 0; i &lt; spaces; i++){
                  sp += " ";
              }
              t = p.hasMoreCommands();
              a1 = p.arg1();
              alen = (10 - a1.length());
              for(int i= 0; i &lt; alen; i++){
                  asp += " ";
              }
              //a2 = p.arg2();
              if (ctype == "C_PUSH" || ctype == "C_POP" || ctype == "C_FUNCTION" || ctype == "C_CALL") {
                  a2 = p.arg2(); 
                  bw.write(ctype + sp + a1 + asp + a2);
              }
              else {
                  bw.write(ctype + sp + a1);
              }
              p.advance();
              ctype = p.commandType();
              len = ctype.length();
              spaces = 13 - len;
          }
  
          bw.flush();
          bw.close();
      }
      catch(FileNotFoundException ex){
          System.out.println("File not found!");
      }
      catch(IOException ex){
          System.out.println("Error reading file '"  + fileName + "'");
      }
    }
  }
  </code></pre>
  
  <p>I went through debugger and it literally goes the entire file then gives me an error when its finished.</p>