无法在Android上使用JaudioTagger - 与Jaudio一起使用NoClassDefFoundError

时间:2013-02-06 13:03:46

标签: android

在我的项目属性中,我将Jaudiotagger.jar添加为外部存档。 Eclipse会检测它拥有的类。 这是我的示例代码:

    protected void onListItemClick(ListView l, View v, int position, long id) {
            Cursor cl = ((SimpleCursorAdapter)l.getAdapter()).getCursor();
            cl.moveToPosition(position);
            String loc = cl.getString(cl.getColumnIndex(MediaStore.MediaColumns.DATA));
            try {
                AudioFile f  = AudioFileIO.read(new File(loc));
                Tag tag = f.getTag();
                AudioHeader h = f.getAudioHeader();
                Toast.makeText(this, tag.getFirst(FieldKey.ALBUM), Toast.LENGTH_SHORT).show();
            } 
            catch (Exception e){}

当我点击任何列表项(实际上是一个音频文件)时,应用程序崩溃了。这是logcat日志:

02-06 18:19:52.039: W/dalvikvm(32310): threadid=1: thread exiting with uncaught exception (group=0x40c751f8)
02-06 18:19:52.049: E/AndroidRuntime(32310): FATAL EXCEPTION: main
02-06 18:19:52.049: E/AndroidRuntime(32310): java.lang.NoClassDefFoundError: org.jaudiotagger.audio.AudioFileIO
02-06 18:19:52.049: E/AndroidRuntime(32310):    at com.niteesh.album.art.MainActivity.onListItemClick(MainActivity.java:51)
02-06 18:19:52.049: E/AndroidRuntime(32310):    at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
02-06 18:19:52.049: E/AndroidRuntime(32310):    at android.widget.AdapterView.performItemClick(AdapterView.java:292)
02-06 18:19:52.049: E/AndroidRuntime(32310):    at android.widget.AbsListView.performItemClick(AbsListView.java:1181)
02-06 18:19:52.049: E/AndroidRuntime(32310):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2709)
02-06 18:19:52.049: E/AndroidRuntime(32310):    at android.widget.AbsListView$1.run(AbsListView.java:3464)
02-06 18:19:52.049: E/AndroidRuntime(32310):    at android.os.Handler.handleCallback(Handler.java:605)
02-06 18:19:52.049: E/AndroidRuntime(32310):    at android.os.Handler.dispatchMessage(Handler.java:92)
02-06 18:19:52.049: E/AndroidRuntime(32310):    at android.os.Looper.loop(Looper.java:137)
02-06 18:19:52.049: E/AndroidRuntime(32310):    at android.app.ActivityThread.main(ActivityThread.java:4511)
02-06 18:19:52.049: E/AndroidRuntime(32310):    at java.lang.reflect.Method.invokeNative(Native Method)
02-06 18:19:52.049: E/AndroidRuntime(32310):    at java.lang.reflect.Method.invoke(Method.java:511)
02-06 18:19:52.049: E/AndroidRuntime(32310):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
02-06 18:19:52.049: E/AndroidRuntime(32310):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
02-06 18:19:52.049: E/AndroidRuntime(32310):    at dalvik.system.NativeStart.main(Native Method)

我还在SO的另一个帖子中添加了TagOptionSingleton.getInstance().setAndroid(true);。当我点击项目然后,它说

java.lang.NoClassDefFoundError: org.jaudiotagger.tag.TagOptionSingleton;

有人可以帮助我在哪里出错吗?

2 个答案:

答案 0 :(得分:0)

您所做的事情允许Eclipse中的代码进行编译,但不会将jar文件添加到APK。您需要在项目根目录中创建一个名为“libs”的目录,并将jar文件添加到该目录中。希望对你有用。

答案 1 :(得分:0)

Android不支持Java声音API,即使您手动将其添加到项目中,也可能遇到命名空间问题。