当前位置: 首页 > news >正文

网站模块在线制作邢台网站建设策划

网站模块在线制作,邢台网站建设策划,公司做两个网站,怎么利用互联网平台赚钱点击跳转Unity3D特效百例点击跳转案例项目实战源码点击跳转游戏脚本-辅助自动化点击跳转Android控件全解手册点击跳转Scratch编程案例点击跳转软考全系列 #x1f449;关于作者 专注于Android/Unity和各种游戏开发技巧#xff0c;以及各种资源分享Unity3D特效百例点击跳转案例项目实战源码点击跳转游戏脚本-辅助自动化点击跳转Android控件全解手册点击跳转Scratch编程案例点击跳转软考全系列 关于作者 专注于Android/Unity和各种游戏开发技巧以及各种资源分享网站、工具、素材、源码、游戏等 有什么需要欢迎底部卡片私我交流让学习不再孤单。 实践过程 解决 今天突然收到一个异常的崩溃信息 解决方案其实很简单 Fragemnt需要一个无参的构造参数且是public类型的多人合作开发项目要注意这个构造参数是不是 public 类型 结论 总结一句话就是这个错误原因是 Fragment 的有参构造函数上。当 Fragment 因为某种原因如横竖屏切换重新创建时会调用到onCreate方法传入之前保存的状态在instantiate方法中通过反射无参构造函数创建一个Fragment并且为Arguments初始化为原来保存的值而此时如果没有无参构造函数就会抛出异常造成程序崩溃。 所以我们强烈推荐使用setArguments和getArguments进行存取参数。 原因 知道怎么解决我们就看看出现这个问题的原因是什么 我们先来看一下Fragment的构造函数 /*** Default constructor. strongEvery/strong fragment must have an* empty constructor, so it can be instantiated when restoring its* activitys state. It is strongly recommended that subclasses do not* have other constructors with parameters, since these constructors* will not be called when the fragment is re-instantiated; instead,* arguments can be supplied by the caller with {link #setArguments}* and later retrieved by the Fragment with {link #getArguments}.** pApplications should generally not implement a constructor. Prefer* {link #onAttach(Context)} instead. It is the first place application code can run where* the fragment is ready to be used - the point where the fragment is actually associated with* its context. Some applications may also want to implement {link #onInflate} to retrieve* attributes from a layout resource, although note this happens when the fragment is attached.*/ public Fragment() { }注释说明 默认构造器。 每一个Fragment必须有一个无参的构造函数以便当Activity恢复状态时fragment可以实例化。 强烈建议fragment的子类不要有其他的有参构造函数因为当fragment重新实例化时不会调用这些有参构造函数 如果要传值应该使用setArguments方法在需要获取这些值时调用getArguments方法。 注释力明确说明了使用有参构造函数会出问题建议使用无参构造函数但是并没有告诉我们具体是哪里的问题。我们在Fragment中直接Ctrl F 搜索 Unable to instantiate fragment发现抛出异常的地方反射无参构造方法在instantiate方法中抛出的。 public static Fragment instantiate(Context context, String fname, Nullable Bundle args) {try {Class? clazz sClassMap.get(fname);if (clazz null) {// Class not found in the cache, see if its real, and try to add itclazz context.getClassLoader().loadClass(fname);sClassMap.put(fname, clazz);}Fragment f (Fragment) clazz.getConstructor().newInstance();if (args ! null) {args.setClassLoader(f.getClass().getClassLoader());f.setArguments(args);}return f;} catch (ClassNotFoundException e) {throw new InstantiationException(Unable to instantiate fragment fname : make sure class name exists, is public, and has an empty constructor that is public, e);} catch (java.lang.InstantiationException e) {throw new InstantiationException(Unable to instantiate fragment fname : make sure class name exists, is public, and has an empty constructor that is public, e);} catch (IllegalAccessException e) {throw new InstantiationException(Unable to instantiate fragment fname : make sure class name exists, is public, and has an empty constructor that is public, e);} catch (NoSuchMethodException e) {throw new InstantiationException(Unable to instantiate fragment fname : could not find Fragment constructor, e);} catch (InvocationTargetException e) {throw new InstantiationException(Unable to instantiate fragment fname : calling Fragment constructor caused an exception, e);} }仔细看代码分析分析Fragment 实例化通过调用类对象的getConstructor()方法获取构造器对象并调用了newInstance()方法创建对象。此时还会将args参数设置给Fragment。具体报错的地方我们是找到了但是这个方法是在哪里调用触发的呢在Fragment没有找到调用的地方由于Fragment是由FragmentManager管理的在该类发现是在restoreAllState方法中调用的。 void restoreAllState(Parcelable state, FragmentManagerNonConfig nonConfig) {// Build the full list of active fragments, instantiating them from// their saved state.mActive new SparseArray(fms.mActive.length);for (int i0; ifms.mActive.length; i) {FragmentState fs fms.mActive[i];if (fs ! null) {FragmentManagerNonConfig childNonConfig null;if (childNonConfigs ! null i childNonConfigs.size()) {childNonConfig childNonConfigs.get(i);}ViewModelStore viewModelStore null;if (viewModelStores ! null i viewModelStores.size()) {viewModelStore viewModelStores.get(i);}Fragment f fs.instantiate(mHost, mContainer, mParent, childNonConfig,viewModelStore);if (DEBUG) Log.v(TAG, restoreAllState: active # i : f);mActive.put(f.mIndex, f);// Now that the fragment is instantiated (or came from being// retained above), clear mInstance in case we end up re-restoring// from this FragmentState again.fs.mInstance null;}}... } 这方法名意为恢复所有的状态而其中注释为创建激活Fragment的列表并将他们从保存的状态中实例化。这个方法应该是Fragment重新实例化时调用的方法。 至此我们就知道什么原因了。 其他 作者小空和小芝中的小空 转载说明-务必注明来源https://zhima.blog.csdn.net/ 这位道友请留步☁️我观你气度不凡谈吐间隐隐有王者霸气日后定有一番大作为旁边有点赞收藏今日传你点了吧未来你成功☀️我分文不取若不成功⚡️也好回来找我。 温馨提示点击下方卡片获取更多意想不到的资源。
http://www.yutouwan.com/news/90377/

相关文章:

  • 做网站公司哪家公司好看手机的网站叫什么
  • 网页游戏网站哪个最好证书兼职的正规平台哪里有
  • 网站建设企业 熊掌号做网站应该问客户什么需求
  • 域名网站可以做多个品牌产品吗桔子seo
  • 阿里巴巴网站做方案网站热点关键词
  • 北京做网站男生工资外贸seo网站大全
  • 做网站签合同个人网站做联盟营销
  • 网页制作网站开发中国网站备案信息查询
  • 网站建设的作业模板宽带多少钱一个月
  • 教育培训网站制作检察院网站建设标书
  • 贵州省住房和城乡建设部官方网站wordpress 没有上级目录的写权限
  • 新媒体包不包括公司网站的建设WordPress分享到微博代码
  • 公司电商网站开发上海高端工作室网站
  • 电子商务网站建设的需求制作企业网站的一般流程
  • 在线购物网站的设计与实现云南做网站多少钱
  • 凡度网络北京网站建设公司山东网站建设报价
  • 深圳外贸网站开发建设网站推广具体内容
  • 青海省建设监理协会网站注册网站借钱平台犯不犯法
  • 站长工具查询官网企业风首页中文官网模板
  • 凡科网免费网站域名注册平面网页设计
  • 做一个网站要注意什么东西wordpress镜像下载
  • 品牌网站建站目的国家化妆品备案网官网
  • 黑龙江省建设厅网站站长wordpress免费域名
  • 有网站模板怎么做网站wordpress支付宝微信支付
  • 浦东新区苏州网站建设什么语言做网站
  • 杰瑞网站建设长沙网站建设zh68
  • 网站建设和空间w网站链接如何做脚注
  • 榆林网站seo中国网站建设总部在哪里
  • 展示型网站举例网站建设都用哪些软件
  • 网站设计师培训图片进行网站开发的所有步骤