无法实例片段 [英] Unable to instantiate Fragment

查看:156
本文介绍了无法实例片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法实例片段确保类名称存在,是公开的,   并且有一个空的构造是公共

Unable to instantiate fragment make sure class name exists, is public, and has an empty constructor that is public

难道是因为我的片段是不是一个静态类? 难道是因为我的片段是一个内部类?

Is it because my Fragment is not a static class? Is it because my Fragment is an inner class?

如果我让我的片段静态类,我所有的引用findViewById失败,这意味着重构了很多。

If I make my Fragment a static class, all my references to findViewById fail, which means a LOT of refactoring.

我怎样才能解决这个不把我内心片段到一个静态类?

How can I solve this without turning my inner Fragment into a static class?

推荐答案

由于CommonsWare说让静态的或独立的,另外不知道为什么你需要重构为得到一个shedload findViewById 工作。建议:

As CommonsWare said make it static or standalone, additionally don't know why you need a shedload of refactoring for getting findViewById to work. Suggestions:

使用膨胀的 onCreateView

inflatedView.findViewById(.....)

,或称其为 onActivityCreated(.....)

getActivity().findViewById(......)

但是,即使你仍然需要重构那么的负载可能只是事情是这样的,将一个应用程序使用的碎片不来免费的有刚刚完成的一个项目这样做。

But even if you still need a load of refactoring then that might just be the way it is, converting an app to use fragments doesn't come for free having just finished a project doing so.

这篇关于无法实例片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆