使用内容解析程序创建播放列表会在Android 5.0版上运行的Amazon设备上抛出NullPointerException。 它适用于所有其他设备。
抛出NPE的类方法:
public static long createPlaylist(final Context context,final String
pname) {
Uri uri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
ContentValues v1 = new ContentValues();
ContentResolver resolver = context.getContentResolver();
v1.put(MediaStore.Audio.Playlists.NAME, pname);
v1.put(MediaStore.Audio.Playlists.DATE_MODIFIED,
System.currentTimeMillis());
resolver.insert(uri, v1); // line 280 throws NPE
...
..
.
}
这是堆栈跟踪(Thanks crashlytics)
Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'boolean java.lang.String.contains(java.lang.CharSequence)' on a null object reference
android.os.Parcel.readException (Parcel.java:1554)
android.content.ContentResolver.insert (ContentResolver.java:1207)
com.musicplayer.Utilities.createPlaylist (Utilities.java:280)
com.musicplayer.Utilities$3.onClick (Utilities.java:333)
android.support.v7.app.AlertController$ButtonHandler.handleMessage (AlertController.java:153)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:771)
可能的解决方案或建议将不胜感激。 谢谢。