0

在我的项目属性中,我将 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)

我还添加TagOptionSingleton.getInstance().setAndroid(true);了 SO 的另一个线程中提到的内容。然后当我点击项目时,它说

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

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

4

2 回答 2

0

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

于 2013-02-06T13:51:49.517 回答
0

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

于 2013-03-14T06:37:06.023 回答