为啥它给我一个错误参数不能为空?
Posted
技术标签:
【中文标题】为啥它给我一个错误参数不能为空?【英文标题】:Why it gives me an error Argument must not be null?为什么它给我一个错误参数不能为空? 【发布时间】:2021-04-02 07:38:30 【问题描述】:请解释为什么它给我一个错误参数不能为空?也许这是因为照片应该显示在片段而不是活动中。你能解释一下吗,我真的想不通。我认为问题出在这行代码 userImage = itemView. findViewById(R.id.RoundedLayoutUsers);但究竟出了什么问题……
public class UserAdapter extends RecyclerView.Adapter<UserAdapter.UserViewHolder>
private List<UserModel> list;
private Context mActivity;
private DatabaseReference rootReference = FirebaseDatabase.getInstance().getReference();
private String currentUserID = FirebaseAuth.getInstance().getCurrentUser().getUid();
public UserAdapter(Context mActivity, List<UserModel> list)
this.list = list;
this.mActivity = mActivity;
@NonNull
@Override
public UserViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
return new UserViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_user,parent,false));
@Override
public void onBindViewHolder(@NonNull UserViewHolder holder, int position)
UserModel user = list.get(position);
// Picasso.get().load(user.urlImage).into(holder.userImage);
Glide.with(mActivity)
.load(user.urlImage)
.circleCrop()
.into(holder.userImage);
@Override
public int getItemCount()
return list.size();
class UserViewHolder extends RecyclerView.ViewHolder
RoundedImageView userImage;
TextView loginName;
RatingBar ratingBar;
public UserViewHolder(@NonNull View itemView)
super(itemView);
userImage = itemView.findViewById(R.id.RoundedLayoutUsers);
这是完整的错误代码
E/androidRuntime: FATAL EXCEPTION: main
Process: com.example.chatden, PID: 9146
java.lang.NullPointerException: Argument must not be null
at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:29)
at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:23)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:669)
at com.example.chatden.adapter.UserAdapter.onBindViewHolder(UserAdapter.java:60)
at com.example.chatden.adapter.UserAdapter.onBindViewHolder(UserAdapter.java:32)
at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7065)
at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7107)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6012)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6279)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
at androidx.recyclerview.widget.LayoutState.next(LayoutState.java:98)
at androidx.recyclerview.widget.StaggeredGridLayoutManager.fill(StaggeredGridLayoutManager.java:1607)
at androidx.recyclerview.widget.StaggeredGridLayoutManager.onLayoutChildren(StaggeredGridLayoutManager.java:683)
at androidx.recyclerview.widget.StaggeredGridLayoutManager.onLayoutChildren(StaggeredGridLayoutManager.java:605)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
at android.view.View.layout(View.java:16659)
at android.view.ViewGroup.layout(ViewGroup.java:5452)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
at android.view.View.layout(View.java:16659)
at android.view.ViewGroup.layout(ViewGroup.java:5452)
at androidx.viewpager.widget.ViewPager.onLayout(ViewPager.java:1775)
at android.view.View.layout(View.java:16659)
at android.view.ViewGroup.layout(ViewGroup.java:5452)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
at android.view.View.layout(View.java:16659)
at android.view.ViewGroup.layout(ViewGroup.java:5452)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16659)
at android.view.ViewGroup.layout(ViewGroup.java:5452)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16659)
at android.view.ViewGroup.layout(ViewGroup.java:5452)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16659)
at android.view.ViewGroup.layout(ViewGroup.java:5452)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16659)
at android.view.ViewGroup.layout(ViewGroup.java:5452)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2706)
at android.view.View.layout(View.java:16659)
at android.view.ViewGroup.layout(ViewGroup.java:5452)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2216)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1976)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1124)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6072)
我想知道如果你运行毕加索然后写目标一定不能为空。
【问题讨论】:
因为该视图中不存在该名称的视图。这是函数返回 null 的唯一原因。确保您使用了正确的名称和布局文件。 查过了。Id重合... 我想知道如果你运行毕加索然后写目标不能为空。 【参考方案1】:user.urlImage
很可能为空。调试UserModel user = list.get(position);
这一行,检查用户对象。
【讨论】:
holder.userImage
怎么样?
我认为那里一切正常,事实是在此之前我正在展示带有数据库图片的必要磁带。然后标记文件是RelativeLayout,有ImageView,一切都很好。但是我看了com.makeramen.roundedimageview.RoundedImageView上的教程。他坚持使用RelativeLayout,但他们没有在ImageView中写入。所以我删除了我的。而在 onBindViewHolder 我指的是 id com.makeramen.roundedimageview.RoundedImageView 如教程所示......我想知道如果你运行毕加索然后写目标不能为空。以上是关于为啥它给我一个错误参数不能为空?的主要内容,如果未能解决你的问题,请参考以下文章
Schema graphql 错误给出“不能为不可为空的字段 Organisation.id 返回 null”为啥?