title: Editing MP3 tags
body: <p>Does anyone of you know a way to edit the tags of an mp3 file?<br>
  I tried Mp3agic but it crash when I try to declare an <em>MP3File</em> object and I also tried tha jaudiotagger library, but it also crashes.</p>
  
  <p>I need help please.</p>
  
  <p>UPDATE:</p>
  
  <p>This is the code snippet where the app crash:</p>
  
  <pre><code>     File testFile = new File(Environment.getExternalStorageDirectory(),"/Music/test.mp3");
          TagOptionSingleton.getInstance().setAndroid(true);
  
          AudioFile audioFile = AudioFileIO.read(testFile);
  
          Tag newTag = audioFile.getTag();
          newTag.setField(FieldKey.ALBUM, this.album);
          newTag.setField(FieldKey.ARTIST,this.artist);
  
          audioFile.commit();
  </code></pre>
  
  <p>The app crash at the line</p>
  
  <pre><code>AudioFile audioFile = AudioFileIO.read(testFile);
  </code></pre>
  
  <p>without exception.</p>
  
  <p>By following all debug steps from the aforementioned line, the app crash at line 246 of the MP3File class of JAudioTagger.
  This is the lines:</p>
  
  <pre><code>..
  finally {
          if(newFile != null) {
              newFile.close();
          }
  </code></pre>
  
  <h2>    ..</h2>
  
  <p>So I tried to change my code here (I changed the AudioFile declaration):</p>
  
  <pre><code>File testFile = new File(Environment.getExternalStorageDirectory(),"/Music/test.mp3");
          TagOptionSingleton.getInstance().setAndroid(true);
  
          AudioFile audioFile = new AudioFile();
          audioFile.setFile(testFile);
  
          Tag newTag = audioFile.getTag();
          newTag.setField(FieldKey.ALBUM, this.album);
          newTag.setField(FieldKey.ARTIST,this.artist);
  
          audioFile.commit();
  </code></pre>
  
  <p>And at line </p>
  
  <pre><code>AudioFile audioFile = new AudioFile();
  </code></pre>
  
  <p>it throw a NullPointerException at line 232 of MP3File class (the line tries to find the header of the file):</p>
  
  <pre><code>audioFile: Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.jaudiotagger.audio.AudioFile.toString()
  </code></pre>
  
  <p>This exception cause in the next lines this exception:</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke interface method 'void org.jaudiotagger.tag.Tag.setField(org.jaudiotagger.tag.FieldKey, java.lang.String)' on a null object reference
  </code></pre>
  
  <p>At line:</p>
  
  <pre><code>newTag.setField(FieldKey.ALBUM, this.album);
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>I tried also to change the line:</p>
  
  <pre><code>Tag newTag = audioFile.getTag();
  </code></pre>
  
  <p>To:</p>
  
  <pre><code>Tag newTag = audioFile.getTagOrCreateAndSetDefault();
  </code></pre>
  
  <p>But it throw this exception:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to create default tag for this file format
  </code></pre>