Rikka仿网易云音乐项目,点击云村,其他人分享的音乐报错
Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference
报错文件
person/adapter/UserEventAdapter.java
代码
rlShare.setOnClickListener(v -> {
intent.setClass(mContext, SongActivity.class);
SongInfo songInfo = new SongInfo();
if (jsonBean.getSong() != null) {
UserEventJsonBean.SongBean songBean = new UserEventJsonBean.SongBean();
songInfo.setDuration(songBean.getDuration());
// 报错行数310
songInfo.setArtist(songBean.getArtists().get(0).getName()); // 作者名
songInfo.setSongId(String.valueOf(songBean.getId())); // 歌曲ID
songInfo.setSongUrl(SONG_URL + songInfo.getSongId() + ".mp3"); // 歌曲URl
songInfo.setSongName(songBean.getName()); // 歌曲名称
songInfo.setSongCover(songBean.getAlbum().getBlurPicUrl()); // 歌曲图片URL
}
因为怕获取的URL内容过旧,有尝试过把UserEventJsonBean内容全部重写一遍
他这里应该是写的时候复制错了,你改成下面这个试试
if (jsonBean.getSong() != null) {
UserEventJsonBean.SongBean songBean =jsonBean.getSong();//应该是这行写错了,换成这样写
songInfo.setDuration(songBean.getDuration());
// 报错行数310
songInfo.setArtist(songBean.getArtists().get(0).getName()); // 作者名
songInfo.setSongId(String.valueOf(songBean.getId())); // 歌曲ID
songInfo.setSongUrl(SONG_URL + songInfo.getSongId() + ".mp3"); // 歌曲URl
songInfo.setSongName(songBean.getName()); // 歌曲名称
songInfo.setSongCover(songBean.getAlbum().getBlurPicUrl()); // 歌曲图片URL
}
这个 songBean 是在
UserEventJsonBean.SongBean songBean = new UserEventJsonBean.SongBean();
新建的,然后没有给他设置 artists ,因此 artists 一定是为 null , 所以调用的时候报错了,可以仔细检查下别人是怎么写的。