我正在为Android制作一个ID3标签编辑器,以便用我的java基础知识做一些实用的方法。我将JAudioTagger库添加到Eclipse项目构建路径中,Eclipse正确地看到它。我的应用程序编译并运行,但是一旦我选择了MP3进行编辑,应用程序就会在尝试加载标记信息时关闭。
有关如何解决此问题的任何建议?我是否错误地初始化了库,或者是否与不正确的构建路径有关?
EditActivity.java:
import java.io.File;
import java.io.IOException;
import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.audio.AudioHeader;
import org.jaudiotagger.audio.exceptions.CannotReadException;
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
import org.jaudiotagger.tag.FieldKey;
import org.jaudiotagger.tag.Tag;
import org.jaudiotagger.tag.TagException;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.ImageView;
public class EditActivity extends Activity
{
AudioFile audioFile = null;
Tag audioTag = null;
AudioHeader audioHeader = null;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit);
// Get our target file from the passed intent's extras
Intent i = getIntent();
String SONG_DATA = i.getStringExtra("SONG_DATA");
File targetFile = new File(SONG_DATA);
try
{
// Open File
audioFile = AudioFileIO.read(targetFile);
audioTag = audioFile.getTag();
audioHeader = audioFile.getAudioHeader();
// set its info to fields
EditText editTrackNum = (EditText) findViewById(R.id.edit_trackNum);
EditText editTrackNumTotal = (EditText) findViewById(R.id.edit_trackNumTotal);
EditText editDiscNum = (EditText) findViewById(R.id.edit_discNum);
EditText editDiscNumTotal = (EditText) findViewById(R.id.edit_discNumTotal);
EditText editArtist = (EditText) findViewById(R.id.edit_artist);
EditText editAlbum = (EditText) findViewById(R.id.edit_album);
EditText editGenre = (EditText) findViewById(R.id.edit_genre);
if (audioTag != null)
{
editTrackNum.setText(audioTag.getFirst(FieldKey.TRACK));
editTrackNumTotal.setText(audioTag.getFirst(FieldKey.TRACK_TOTAL));
editDiscNum.setText(audioTag.getFirst(FieldKey.DISC_NO));
editDiscNumTotal.setText(audioTag.getFirst(FieldKey.DISC_TOTAL));
editArtist.setText(audioTag.getFirst(FieldKey.ARTIST));
editAlbum.setText(audioTag.getFirst(FieldKey.ALBUM));
editGenre.setText(audioTag.getFirst(FieldKey.GENRE));
// get cover art
ImageView editImage = (ImageView) findViewById(R.id.edit_image);
Bitmap image = BitmapFactory.decodeFile(audioTag.getFirst(FieldKey.COVER_ART));
editImage.setImageBitmap(image);
}
}
catch (CannotReadException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (TagException e)
{
e.printStackTrace();
}
catch (ReadOnlyFileException e)
{
e.printStackTrace();
}
catch (InvalidAudioFrameException e)
{
e.printStackTrace();
}
}
}
logcat的:
E/dalvikvm(27537): Could not find class 'sun.nio.ch.DirectBuffer', referenced from method org.jaudiotagger.audio.mp3.MP3File.readV2Tag
W/dalvikvm(27537): VFY: unable to resolve check-cast 1179 (Lsun/nio/ch/DirectBuffer;) in Lorg/jaudiotagger/audio/mp3/MP3File;
D/dalvikvm(27537): VFY: replacing opcode 0x1f at 0x006f
E/dalvikvm(27537): Could not find class 'sun.nio.ch.DirectBuffer', referenced from method org.jaudiotagger.audio.mp3.MP3File.readV2Tag
W/dalvikvm(27537): VFY: unable to resolve check-cast 1179 (Lsun/nio/ch/DirectBuffer;) in Lorg/jaudiotagger/audio/mp3/MP3File;
D/dalvikvm(27537): VFY: replacing opcode 0x1f at 0x00af
D/dalvikvm(27537): VFY: dead code 0x0071-0077 in Lorg/jaudiotagger/audio/mp3/MP3File;.readV2Tag (Ljava/io/File;II)V
D/dalvikvm(27537): VFY: dead code 0x00b1-00b7 in Lorg/jaudiotagger/audio/mp3/MP3File;.readV2Tag (Ljava/io/File;II)V
D/AndroidRuntime(27537): Shutting down VM
W/dalvikvm(27537): threadid=1: thread exiting with uncaught exception (group=0x401ef560)
E/AndroidRuntime(27537): FATAL EXCEPTION: main
E/AndroidRuntime(27537): java.lang.NoClassDefFoundError: sun.nio.ch.DirectBuffer
E/AndroidRuntime(27537): at org.jaudiotagger.audio.mp3.MP3File.readV2Tag(MP3File.java:252)
E/AndroidRuntime(27537): at org.jaudiotagger.audio.mp3.MP3File.<init>(MP3File.java:466)
E/AndroidRuntime(27537): at org.jaudiotagger.audio.mp3.MP3FileReader.read(MP3FileReader.java:39)
E/AndroidRuntime(27537): at org.jaudiotagger.audio.AudioFileIO.readFile(AudioFileIO.java:288)
E/AndroidRuntime(27537): at org.jaudiotagger.audio.AudioFileIO.read(AudioFileIO.java:151)
E/AndroidRuntime(27537): at com.eccproductions.audioid.EditActivity.onCreate(EditActivity.java:44)
E/AndroidRuntime(27537): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(27537): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
E/AndroidRuntime(27537): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
E/AndroidRuntime(27537): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
E/AndroidRuntime(27537): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
E/AndroidRuntime(27537): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(27537): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(27537): at android.app.ActivityThread.main(ActivityThread.java:3835)
E/AndroidRuntime(27537): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(27537): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(27537): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
E/AndroidRuntime(27537): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
E/AndroidRuntime(27537): at dalvik.system.NativeStart.main(Native Method)