最近使用Viewpager + Fragment来做应用,经常会遇到如下错误
E/UncaughtException-main(13661): java.lang.RuntimeException: Unable to start activity ComponentInfo{......}: android.app.Fragment$InstantiationException: Unable to instantiate fragment xxxxxx...: make sure class name exists, is public, and has an empty constructor that is public解决办法:
自定义的fragment 如果只定义了带参数的构造方法,那么要把参数为空的构造函数一并写上。原因待进一步研究,知道的朋友不吝赐教!
本文探讨了在使用Viewpager+Fragment时,遇到的无法启动Activity的异常问题,具体为RuntimeException和Fragment$InstantiationException。通过分析发现,自定义Fragment仅定义了带参数的构造方法时,需要确保添加参数为空的构造函数。本文提供了解决方法并解释了其背后的原因。
1万+

被折叠的 条评论
为什么被折叠?



