片段中RecyclerView中的文本视图不';t显示来自Java或XML文件的任何文本

片段中RecyclerView中的文本视图不';t显示来自Java或XML文件的任何文本,java,android,android-layout,android-recyclerview,Java,Android,Android Layout,Android Recyclerview,编辑我的问题标题 我试图将JSON数据传递到一个构建在片段中的RecyclerView中,实际上我是在装饰RecyclerView的list_items.xml之前完成的 现在我正试图在这个回收器视图中显示一些普通文本,并且一如既往地在MyViewHolder的行中给我一个NullPointerException…在我对该行进行注释后,应用程序运行,但回收器视图不显示任何文本,甚至连回收器视图列表中的文本都不显示 这是我到目前为止得到的结果,recyclerView只显示ImageView。 而

编辑我的问题标题 我试图将JSON数据传递到一个构建在片段中的RecyclerView中,实际上我是在装饰RecyclerView的list_items.xml之前完成的

现在我正试图在这个回收器视图中显示一些普通文本,并且一如既往地在MyViewHolder的行中给我一个NullPointerException…在我对该行进行注释后,应用程序运行,但回收器视图不显示任何文本,甚至连回收器视图列表中的文本都不显示

这是我到目前为止得到的结果,recyclerView只显示ImageView。 而且文本视图不起作用

公共类MyRecyclerAdapter扩展了RecyclerView.Adapter{
私有上下文;私有列表;
ForumsFragment片段=新的ForumsFragment();
//定义contenxt和listItem的构造函数
公共MyRecyclerAdapter(上下文、列表项){
this.context=上下文;
forumsListItems=项目;
}
@非空
@凌驾
public MyRecyclerAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup父级,int-viewType){
视图v=LayoutInflater.from(parent.getContext())
.充气(R.layout.forums\u listitems,父项,false);
返回新的MyViewHolder(v);
}
/*从MyViewHolder绑定所有内容*/
@凌驾
public void onBindViewHolder(@NonNull MyViewHolder,int位置){
//定义列表项位置
ForumsListItem=forumsListItems.get(位置);
//在bindingViewHolder中调用textView
//holder.catListName.setText(listItem.getCatlistName());
holder.numodailynewposts.setText(listItem.getNumOftodayPosts());
holder.descriptTv.setText(listItem.getDescription());
}
@凌驾
public int getItemCount(){
返回forumslititems.size();
}
公共类MyViewHolder扩展了RecyclerView.ViewHolder实现了View.OnClickListener{
私有文本视图名称TV、descriptTv、numOfDailyNewPosts、catListName;
私人ImageView imgIcons;
公共MyViewHolder(查看项目视图){
超级(项目视图);
//以列表形式显示的内容
descriptTv=(TextView)itemView.findViewById(R.id.item_detail);
catListName=(TextView)itemView.findViewById(R.id.catListTxt);
numOfDailyNewPosts=(TextView)itemView.findViewById(R.id.numOfDailyNewPosts);
//可以在此处添加Picaso纹理图像
setOnClickListener(这个);
}
@凌驾
公共void onClick(视图v){
int pos=getAdapterPosition();
//获取当前位置
forumsListItems=forumsListItems.get(pos);
Toast.makeText(上下文,items.getForumsTitles(),Toast.LENGTH_LONG.show();
//点击功能
}
}
}

My list_items.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/cardview_compat_inset_shadow"
    android:layout_marginTop="5dp"
    android:layout_marginEnd="5dp"
    android:layout_marginStart="5dp"
    android:padding="16dp" >
    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/color_light_yellow">
            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <ImageView
                    android:id="@+id/forumsTitleImg"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    app:layout_constraintHorizontal_chainStyle="packed"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    android:src="@android:drawable/checkbox_on_background"/>
                <TextView
                    android:id="@+id/numOfDailyNewPosts"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="fdlksfjsdlkjf"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintStart_toEndOf="@id/forumsTitleImg"
                    android:layout_margin="10dp" />
            </android.support.constraint.ConstraintLayout>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/item_detail"
            android:layout_margin="10dp"
            app:layout_constraintTop_toBottomOf="@+id/frame"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent" />
    </android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>

06-03 23:07:30.7522964-2964/?I/art:Late-enabling-Xcheck:jni 06-03 23:07:30.930 2964-2964/com.yamibo.bbs.splashscreen W/art:execv失败(/system/bin/dex2oat--runtime arg-classpath--runtime arg-Xms64m--runtime arg-Xmx512m--instruction set variant=krait--instruction set features=smp,div,atomic_ldrd_strd--runtime arg-Xrelocate--boot image=/system/framework/boot.art--runtime arg Xms64m--xmxmx512--instruction set variant=krait--instruction set features=default--dex file=/data/.yamibo.bbs.splashscreen-2/split_lib_dependencies_apk.apk--oat file=/data/dalvik cache/arm/data@app@com.yamibo.bbs.splashscreen-2@split_lib_dependencies_apk.apk@类。dex),因为非0退出状态 06-03 23:07:31.416 2964-2964/com.yamibo.bbs.splashscreen W/art:execv失败(/system/bin/dex2oat--runtime arg-classpath--runtime arg-Xms64m--runtime arg-Xmx512m--instruction set variant=krait--instruction set features=smp,div,atomic_ldrd_strd--runtime arg-Xrelocate--boot image=/system/framework/boot.art--runtime arg Xms64m--xmxmx512--instruction set variant=krait--instruction set features=default--dex file=/data/.yamibo.bbs.splashscreen-2/split_lib_slice_0_apk.apk--oat file=/data/dalvik cache/arm/data@app@com.yamibo.bbs.splashscreen-2@split_lib_slice_0_apk.apk@类。dex),因为非0退出状态 06-03 23:07:31.493 2964-2964/com.yamibo.bbs.splashscreen W/art:execv失败(/system/bin/dex2oat--runtime arg-classpath--runtime arg-Xms64m--runtime arg-Xmx512m--instruction set variant=krait--instruction set features=smp,div,atomic_ldrd_strd--runtime arg-Xrelocate--boot image=/system/framework/boot.art--runtime arg Xms64m--xmxmx512--instruction set variant=krait--instruction set features=default--dex file=/data/.yamibo.bbs.splashscreen-2/split_lib_slice_1_apk.apk--oat file=/data/dalvik cache/arm/data@app@com.yamibo.bbs.splashscreen-2@split_lib_slice_1_apk.apk@类。dex),因为非0退出状态 06-03 23:07:31.594 2964-2964/com.yamibo.bbs.splashscreen W/art:execv失败(/system/bin/dex2oat--runtime arg-classpath--runtime arg-Xms64m--runtime arg-Xmx512m--instruction set variant=krait--instruction set features=smp,div,atomic_ldrd_strd--runtime arg-Xrelocate--boot image=/system/framework/boot.art--runtime arg Xms64m--xmxmx512--instruction set variant=krait--instruction set features=default--dex file=/data/.yamibo.bbs.splashscreen-2/split_lib_slice_2_apk.apk--oat file=/data/dalvik cache/arm/data@app@com.yamibo.bbs.splashscreen-2@split_lib_slice_2_apk.apk@类。dex),因为非0退出状态 06-03 23:07:31.666 2964-2964/com.yamibo.bbs.splashscreen W/art:execv失败(/system/bin/dex2oat--runtime arg-classpath--runtime arg-Xms64m--runtime arg-Xmx512m--instruction set variant=krait--instruction set features=smp,div,atomic_ldrd_strd--runtime arg-Xrelocate--boot image=/system/framework/boot.art--runtime arg Xms64m--xmxmx512--instruction set variant=krait--instruction set features=default--dex file=/data/.yamibo.bbs.splashscreen-2/split_lib_slice_3_apk.apk--oat file=/data/dalvik cache/arm/
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/cardview_compat_inset_shadow"
    android:layout_marginTop="5dp"
    android:layout_marginEnd="5dp"
    android:layout_marginStart="5dp"
    android:padding="16dp" >
    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/color_light_yellow">
            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <ImageView
                    android:id="@+id/forumsTitleImg"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    app:layout_constraintHorizontal_chainStyle="packed"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    android:src="@android:drawable/checkbox_on_background"/>
                <TextView
                    android:id="@+id/numOfDailyNewPosts"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="fdlksfjsdlkjf"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintStart_toEndOf="@id/forumsTitleImg"
                    android:layout_margin="10dp" />
            </android.support.constraint.ConstraintLayout>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/item_detail"
            android:layout_margin="10dp"
            app:layout_constraintTop_toBottomOf="@+id/frame"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent" />
    </android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="5dp"
    android:layout_marginStart="5dp"
    android:layout_marginTop="5dp"
    android:padding="16dp">

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

        <FrameLayout
            android:id="@+id/frame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

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

                <ImageView
                    android:id="@+id/forumsTitleImg"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:src="@android:drawable/checkbox_on_background" />

                <TextView
                    android:id="@+id/numOfDailyNewPosts"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:text="fdlksfjsdlkjf" />
            </LinearLayout>
        </FrameLayout>

        <TextView
            android:id="@+id/item_detail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp" />
    </LinearLayout>
</android.support.v7.widget.CardView></RelativeLayout>
    public class SampleActivity extends Activity{
    RecyclerView sampleRecycle;
    MyRecyclerAdapter myRecyclerAdapter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sample_activity);

        sampleRecycle = (RecyclerView) findViewById(R.id.sampleRecycle);

        RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
        sampleRecycle.setLayoutManager(mLayoutManager);
        myRecyclerAdapter = new MyRecyclerAdapter(this);
        sampleRecycle.setAdapter(myRecyclerAdapter);
    }


    public class MyRecyclerAdapter extends RecyclerView.Adapter<MyRecyclerAdapter.MyViewHolder> {
        private Context context;
//        private List<ForumsListItem> forumsListItems;
//        ForumsFragment fragment = new ForumsFragment();

        //Define the constructor for both contenxt and listItem
        public MyRecyclerAdapter(Context context) {
            this.context = context;
//            forumsListItems = items;

        }

        @NonNull
        @Override
        public MyRecyclerAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View v = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.list_items, parent, false);

            return new MyViewHolder(v);
        }

        /*Bind everything from te MyViewHolder*/
        @Override
        public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
            //Define listItem position
//            ForumsListItem listItem = forumsListItems.get(position);

            //Calling the textView inside bindingViewHolder
            //holder.catListName.setText(listItem.getCatlistName());
//            holder.numOfDailyNewPosts.setText(listItem.getNumOftodayPosts());
//            holder.descriptTv.setText(listItem.getDescription());
        }

        @Override
        public int getItemCount() {
            return 20;
        }

        public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
            private TextView nameTv, descriptTv, numOfDailyNewPosts, catListName;

            private ImageView imgIcons;

            public MyViewHolder(View itemView) {
                super(itemView);
                //things to display in form of List

                descriptTv = (TextView) itemView.findViewById(R.id.item_detail);
//                catListName = (TextView) itemView.findViewById(R.id.catListTxt);
                numOfDailyNewPosts = (TextView) itemView.findViewById(R.id.numOfDailyNewPosts);
                //can add Picaso loding images here
                itemView.setOnClickListener(this);
            }

            @Override
            public void onClick(View v) {
                int pos = getAdapterPosition();
                //get the current position

//                ForumsListItem items = forumsListItems.get(pos);

//                Toast.makeText(context, items.getForumsTitles(), Toast.LENGTH_LONG).show();
                //On click functionality

            }
        }
    }
}