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

来源:互联网 发布:网络推广月工作计划 编辑:程序博客网 时间:2024/05/21 03:27
在android中使用Fragment中,有时候我们会遇到Unable to instantiate fragment make sure class name exists, is public, and has an empty constructor that is public这样的异常,从字面上理解应该是这个我们的自定义Fragment需要一个public没有参数的构造函数,但是有时候即使加上了无参数的public的构造函数,依然出现这个异常。今天我也遇到了这个问题,原来Fragment不能作为内部类,即使作为内部类,我们也要加上static关键字,是不是内部类不能通过反射来创建实例,这个还要去看看Java相关的知识,希望给遇到这个问题的网友提个醒,自定义Fragment要单独定义,不能作为内部类,否则使用会出问题。
0 0
原创粉丝点击