如何解决 Fragment 无法转换为 Context 错误?

马克先生

在我的片段中,Android Studio 中出现以下错误。错误:不兼容的类型:EmployeeSetaFragment 无法转换为 Context

如何解决?

public class EmployeeSetFragment extends Fragment {

    private RecyclerView recyclerView;
    private PoemAdapter adapter;
    private ArrayList<Poem> employeeArrayList;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_people,container,false);

        employeeArrayList = new ArrayList<>();
        employeeArrayList.add(new Poem("no 1 ", "mark"));

recyclerView = (RecyclerView) v.findViewById(R.id.recycler_view);

            adapter = new PoemAdapter(employeeArrayList);
            RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(EmployeeSetFragment.this);
            recyclerView.setLayoutManager(layoutManager);
            recyclerView.setAdapter(adapter);
            return  v;
桑迪普教区

用这个

RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());

代替

RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(EmployeeSetFragment.this);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何通过解决错误“Activity 无法转换为 Fragment”将 Fragment 传递给类构造函数?

如何解决不可转换的类型,无法将“ Android.support.v4.app.fragment”转换为“ packagename”

Laravel-如何解决类stdClass的对象无法转换为字符串错误

如何解决无法将字符串转换为浮点错误

如何解决错误“无法转换为com.sun.speech.freetts.VoiceDirectory”?

如何解决此错误“类型不匹配:无法从List <String>转换为Iterator <String>”

laravel 表达式无法转换为数字错误如何解决?

如何解决错误 C2440“正在初始化”:无法从“_Ty”转换为“_Objty”

我如何解决错误Illuminate \ Database \ Eloquent \ Collection类的对象无法转换为int

我该如何解决这个 [错误] 无法在赋值中将“float [6]”转换为 float

如何解决 Django 中无法将字符串转换为浮点错误?

如何解决错误:无法将类型“long”隐式转换为“bool”?

如何解决 Matlab 中的“无法从结构转换为双精度”错误

如何修复错误:类型不兼容:MenuFragment 无法在 android 中转换为 Fragment?

如何解决“无法更改常量”错误

如何解决“无法解决groupBy”错误消息?

错误:无法解决:viewpager-如何解决?

如何解决Vue-Formulate无法解决组件错误

如何解决此错误:“ ValueError:无法将字符串转换为float:'-1,89E-09'”?

整数到字符串,如何解决以下错误:“ TypeError:无法将未定义转换为对象”?

使用反应性扩展(RX)如何解决编译错误“无法从'方法组'转换为'System.IObserver”

如何解决此php错误(CI_DB_mysql_result类的对象无法转换为int)

当接口具有多个通用参数时,如何解决“无法将[类型]隐式转换为[接口]”错误?

我如何解决此错误:无法将“NSURL”类型的值转换为预期的参数类型“URLRequest”

如何解决此React Native错误:“ java.lang.String无法转换为com.facebook.react.uimanager”?

如何解决“可恢复的致命错误:类Closure的对象无法在...中转换为字符串”

尝试将序列数据嵌入keras模型时,如何解决“无法将字符串转换为float:”错误

如何解决“无法将'System.Text.RegularExpressions.Match'类型的对象转换为'System.IConvertible”。错误

如何解决git的“无法合并的错误”错误