帮我修复此错误
这是我的logcat
NullPointerException:尝试调用接口方法 ' java.lang.Object [] java.util.Collection.toArray()'在null对象上 参考 ---> membersList.addAll(member);
我尝试初始化并尝试了几次,但没有用。请帮我解决这个问题。
10-14 16:11:09.995 31885-31885/com.designzoos.indj E/UncaughtException: java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.
at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:111)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5551)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object[] java.util.Collection.toArray()' on a null object reference
at java.util.ArrayList.addAll(ArrayList.java:188)
at com.designzoos.indj.presentation.view.adapter.ChooseArtistAdapter.<init>(ChooseArtistAdapter.java:72)
at com.designzoos.indj.presentation.view.activity.ChooseArtistActivity.showMembersData(ChooseArtistActivity.java:155)
at com.designzoos.indj.presentation.presenter.PostArtistPresenter$MembersLikeDataObserver.onNext(PostArtistPresenter.java:75)
at com.designzoos.indj.presentation.presenter.PostArtistPresenter$MembersLikeDataObserver.onNext(PostArtistPresenter.java:54)
at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:198)
at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:250)
at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:109)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5551)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
这是我的适配器
(ChooseArtistAdapter.java:72)---&gt; membersList.addAll(member);
public class ChooseArtistAdapter extends RecyclerView.Adapter<ChooseArtistAdapter.ViewHolder> implements Filterable,SearchView {
private ArrayList<Members>member = new ArrayList<>();
private ArrayList<Members>membersList;
private RecordFilter filter;
Context mContext;
@Inject
PostArtistPresenter postArtistPresenter;
public ChooseArtistAdapter(Context context, ArrayList<Members> member) {
// if(member==null)return;
this.mContext = context;
this.membersList = new ArrayList<>();
this.member = member;
**membersList.addAll(member);**
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_artist_adapter, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder( final ViewHolder holder, int position) {
final Members members = membersList.get(position);
holder.artistName.setText(members.getName());
// if(){
// holder.artistName.setText(members.getName());
// }else if(){
// holder.artistName.setText(members.getGroup()+"
"+members.getName());
// }
Glide.with(mContext)
.load(members.getImageUrl()).listener(new
RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
holder.imageViewPlaceHolder.setVisibility(View.GONE);
return false;
}
})
.into(holder.artist_image_cover);
holder.setItemClickListener(new ItemClickListener() {
boolean isSelectClick=true;
int count =0;
@Override
public void onClick(View view, int position) {
Context context = view.getContext();
if(isSelectClick==true){
holder.selectImage.setVisibility(View.VISIBLE);
isSelectClick=false;
count=1;
//post
((ChooseArtistActivity) context).postPresenter();
}else if(isSelectClick==false){
holder.selectImage.setVisibility(View.GONE);
isSelectClick=true;
count=-1;
//delete
((ChooseArtistActivity) context).deletePresenter();
}
((ChooseArtistActivity)context).setCountText(count);
}
});
}
@Override
public int getItemCount() {
if (null == membersList)
{
return 0;
}else{
return membersList.size();
}
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
@Nullable
@BindView(R.id.imageViewPlaceHolder)
CircularImageView imageViewPlaceHolder;
@Nullable
@BindView(R.id.artist_image_cover)
CircularImageView artist_image_cover;
@Nullable
@BindView(R.id.selectImage)
public
CircularImageView selectImage;
@BindView(R.id.artistName)
TextView artistName;
@Nullable
@BindView(R.id.check)
public TextView check;
private ItemClickListener itemClickListener;
private ChooseArtistActivity chooseArtistActivity;
public ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
itemView.setOnClickListener(this);
//onClick
}
public void setItemClickListener(ItemClickListener itemClickListener){
this.itemClickListener = itemClickListener;
}
@Override
public void onClick(View view) {
itemClickListener.onClick(view,getAdapterPosition());
}
}
答案 0 :(得分:-1)
试
if(member != null)
membersList.addAll(member);