In my project properties , I added Jaudiotagger.jar as an external archive. Eclipse detects the classes it has.
Here is my sample code :
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){}
When I click on any list item (which is actually an audio file) , the app crashes. Here is the logcat log :
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)
I also added TagOptionSingleton.getInstance().setAndroid(true); as mentioned in another thread here at SO. And when I click on item then , it says
java.lang.NoClassDefFoundError: org.jaudiotagger.tag.TagOptionSingleton;
Can someone help where am I going wrong ?
What you did allows the code in Eclipse to compile but doesn’t add the jar file to the APK. You need to create a directory in the project root called “libs” and add the jar file to that. Hope that works for you.