title: Different types doesnt write to file
body: <p>I am creating three text files, and try to write to them from a list. When I have the code like in the first example, nothing is written to the first file, only second or third. If written like in the second code, nothing is written to the first or second file, only third. What is wrong and how can I correct this code so it writes to all three files? The files are created successfully.</p>
  
  <pre><code>class Operasjonsleder{
      PrintWriter skriver=null;
      public void ferdig(ArrayList&lt;Melding&gt; meldinger) throws FileNotFoundException, UnsupportedEncodingException, IOException, NullPointerException{
          ArrayList&lt;Melding&gt; andreMeldinger=new ArrayList&lt;Melding&gt;();
          andreMeldinger=sortere(meldinger);
          int id=0;
          for(int i=0; i&lt;andreMeldinger.size(); i++){
              if(andreMeldinger.get(i).hentID()!=id){ 
                  if(id&gt;1){
                      skriver.close();
                  } 
                  id=andreMeldinger.get(i).hentID();
                  String n=String.valueOf(id);
                  skriver = new PrintWriter(n+".txt", "UTF-8");
              }
              skriver.println(andreMeldinger.get(i).hentInnhold());
              skriver.println("");
              skriver.println("");
          }
          skriver.close();
      }
  
      class Operasjonsleder{
          PrintWriter skriver=null;
          public void ferdig(ArrayList&lt;Melding&gt; meldinger) throws FileNotFoundException, UnsupportedEncodingException, IOException, NullPointerException{
              ArrayList&lt;Melding&gt; andreMeldinger=new ArrayList&lt;Melding&gt;();
              andreMeldinger=sortere(meldinger);
              int id=0;
              for(int i=0; i&lt;andreMeldinger.size(); i++){
                  if(andreMeldinger.get(i).hentID()!=id){
                      if(id&gt;1){
                          skriver.close();
                      }
                      id=andreMeldinger.get(i).hentID();
                      String n=String.valueOf(id);
                      skriver = new PrintWriter(n+".txt", "UTF-8");
                  }
                  skriver.println("Whatever");
                  skriver.println("");
                  skriver.println("");
              }
              skriver.close();
          }
  </code></pre>