I need to get the lyrics from mp3 song
Mp3File mp3file = new Mp3File(file);
if (mp3file.hasId3v2Tag()) {
ID3v2 id3v2Tag = mp3file.getId3v2Tag();
Log.d("Lyrics",id3v2Tag.getLyrics());
}
The above code only I'm using. But its returning "java.lang.NullPointerException". Please help me to solve this issue.
The full crash report
E/AndroidRuntime: FATAL EXCEPTION: main Process: in.example.mp3tag, PID: 10237 java.lang.RuntimeException: Unable to start activity ComponentInfo{in.example.mp3tag/in.example.mp3tag.Main2Activity}: java.lang.NullPointerException: println needs a message at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2904) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2986) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1671) at android.os.Handler.dispatchMessage(Handler.java:108) at android.os.Looper.loop(Looper.java:206) at android.app.ActivityThread.main(ActivityThread.java:6784) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:852) Caused by: java.lang.NullPointerException: println needs a message at android.util.Log.println_native(Native Method) at android.util.Log.d(Log.java:320) at in.example.mp3tag.Main2Activity.onCreate(Main2Activity.java:200) at android.app.Activity.performCreate(Activity.java:6984) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1235) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2857) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2986) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1671) at android.os.Handler.dispatchMessage(Handler.java:108) at android.os.Looper.loop(Looper.java:206) at android.app.ActivityThread.main(ActivityThread.java:6784) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:852)
You're getting an exception because
id3v2Tag.getLyrics()
returnednull
and you're usingLog.d(String tag, String msg)
. See documentation regarding this method here.If you want to use
Log.d
with possible null objects, useLog.d(String tag, String msg, Throwable tr)
. See documentation here.So
id3v2Tag.getLyrics()
returnsnull
. The library you're using offers little documentation but I'm assuminggetLyrics()
returnsnull
in the absence of lyrics, and not an empty string. This may not be an issue for the rest of your code if you test the result ofgetLyrics()
properly, like so: