尝试对空对象引用调用虚拟方法“boolean java.lang.string.contains(java.lang.charsequence)”

c3frrgcw  于 2021-06-26  发布在  Java
关注(0)|答案(1)|浏览(382)

如何修复此错误:
它告诉我错误来自第一行:

//Putting album art in album placeholder

**Error Here-->**if (album_list_of.get(position).getAlbumCover().contains("content://media/external/audio/albumart")) {

                Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
                Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, Integer.parseInt(album_list_of.get(position).getAlbumPosition()));
                Glide.with(this)
                        .load(albumArtUri)
                        .error(R.drawable.no_song_image)
                        .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
                        .into(album_Cover);
            } else {
                BitmapFactory.Options bmOptions = new BitmapFactory.Options();
                Bitmap bitmap = BitmapFactory.decodeFile(album_list_of.get(position).getAlbumCover(), bmOptions);
                if (bitmap != null) {
                    Glide.with(this)
                            .load(bitmap)
                            .error(R.drawable.no_song_image)
                            .into(album_Cover);
                }
            }
2ic8powd

2ic8powd1#

album_list_of.get(position).getAlbumCover() 返回null。为其值添加null检查

String album = album_list_of.get(position).getAlbumCover();

if (album != null)
{
   ...
}

相关问题