I am using a RecylerView to populate CardView items. I am noticing that the 
RecyclerView is generating a NullPointer here, as for some reason the 
RecyclerView references the parent view and not the individual CardView.

I believe the error is occurring here:

      public ViewHolder(View v) {
                super(v);
                userAvatar = (ImageView) findViewById(R.id.profile_image);
                userID = (TextView) findViewById(R.id.user_ID);
                userComment = (TextView) 
findViewById(R.id.user_comment_textview);
            }

Here is my individual CardView XML (individual_comment.xml):

    <android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android";
    xmlns:app="http://schemas.android.com/tools";
    xmlns:card_view="http://schemas.android.com/apk/res-auto";
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    card_view:cardCornerRadius="4dp">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/comment_backgroud_grey"
        android:orientation="horizontal"
        android:padding="@dimen/individual_comment_padding">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/profile_image"
            android:layout_width="@dimen/avatar_image_dimension"
            android:layout_height="@dimen/avatar_image_dimension"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:src="@drawable/empty_avatar_256x256"
            app:civ_border_color="#FF000000"
            app:civ_border_width="@dimen/circle_image_border_width" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/user_ID"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="16dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="16dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:text="Name"
                android:textColor="@color/black"
                android:textSize="@dimen/individual_comment_userID_textsize"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/user_comment_textview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="16dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="16dp"
                android:layout_marginStart="8dp"
                android:hint="This text should be the comment that I Type, 
not the default text I set in the XML."
                android:paddingBottom="1dp"
                android:textColor="@color/black"
                
android:textSize="@dimen/individual_comment_userComment_textsize" />

        </LinearLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>

I am receiving a NullPointer for this line:

     @Override
            public void onBindViewHolder(ViewHolder holder, int position) {
    //nullponter, I believe it is not recognizing "user Comment"           
     holder.userComment.setText(mDataSet.get(position).getUserComment());
                    String x = mDataSet.get(position).getUserComment();
                    Log.v("ON_BIND_VIEW", "THE STRING IS " + x);
                    Log.v("THE_POSITION", "THE POSITION IS " + position);
                }

onCreateViewHolder:
      

      @Override
        public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                       int viewType) {
            // create a new view
            View v = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.individual_comment, parent, false);
            // set the view's size, margins, paddings and layout parameters
            return new ViewHolder(v);
        }

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/e8990599-ae41-4e24-aab7-11a2bbcac3b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to