Recyclerview点击item跳转页面报空指针[复制链接]

public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {

    View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.recy_view_item,viewGroup,false);
    final ViewHolder holder = new ViewHolder(view);
    //点击事件
    holder.relesaTitle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(context,NRCommunityActivity.class);
            context.startActivity(intent);
        }
    });
    return holder;
}
    报错:
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
    at android.content.ComponentName.<init>(ComponentName.java:130)
    at android.content.Intent.<init>(Intent.java:5780)
    at com.prx.newdemo.CommuintyAdapter$1.onClick(CommuintyAdapter.java:44)
小萌新 78查看 · 0回复 · 2019-9-10 23:19 有用(0
共0个回答
需要登入后才可以评论 登录 | 立即注册