Recyclerview没有LayoutManager android studio

Recyclerview没有LayoutManager android studio,android,android-recyclerview,Android,Android Recyclerview,我试图在我的android应用程序中实现RecyclerView,但它给了我一个错误 “RecyclerView没有布局管理器” 即使我在代码中初始化了它。我的java和xml文件: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inf

我试图在我的android应用程序中实现RecyclerView,但它给了我一个错误

“RecyclerView没有布局管理器”

即使我在代码中初始化了它。我的java和xml文件:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.activity_list, container, false);

    mRecyclerView = rootView.findViewById(R.id.recyclerView);

    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
    mRecyclerView.setLayoutManager(layoutManager);

    mAdapter = new CustomAdapter(mDataset);
    mRecyclerView.setAdapter(mAdapter);

    return rootView;
}
XML



您不能将信号活动用于recy。。。。和主要活动。请创建一个新的xml文件,如list_file

您可以尝试将
RecyclerView.LayoutManager
更改为
LinearLayoutManager
吗。这应该可以解决问题,如果不是,您还可以粘贴
CustomAdapter
类的代码。我尝试使用新的xml文件,但它会给我相同的错误
    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".List"
    android:background="@color/black">
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="495dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="parent"/
</androidx.constraintlayout.widget.ConstraintLayout>