Android Studio 常见错误 之 Fragment null must be a public static class to be properly recreated 的问题处理

 

 

Android Studio 常见错误 之 Fragment null must be a public static class to be  properly recreated 的问题处理

 

目录

Android Studio 常见错误 之 Fragment null must be a public static class to be  properly recreated 的问题处理

一、简单介绍

二、解决方法

三、具体方法


 

一、简单介绍

Android Studio 常见错误的整理,为以后遇到类似的错误,能及时解决。

本节介绍,在 Android Studio  使用 new Fragment(){} 的时候 Fragment null must be a public static class to be  properly recreated from instance state.出现问题的处理方法。

 

二、解决方法

原因是:不允许在实例化对象的时候重写方法

我们在使用的时候重新构建一个类,重写 Fragment 的方法即可;这样就不是在实例化对象的时候重写方法了。

 

三、具体方法

1、例如 如下产生的报错

 

2、继承重写 Fragment 类

 

3、这样使用 MyFragment

 

4、这样,报错就没有了

 

猜你喜欢

转载自blog.csdn.net/u014361280/article/details/106585678