关于make sure class name exists, is public, and has an empty constructor that is public解决办法

来源:互联网 发布:软件提速精灵 编辑:程序博客网 时间:2024/05/18 01:30

Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.test.testFragment: make sure class name exists, is public, and has an empty constructor that is public


开发时候遇到一个这样的问题。说我的fragment没初始化。网上找了下资料

参考了http://www.tuicool.com/articles/nU7bAz


根据报错提示 “make sure class name exists, is public, and has an empty constructor that is public” ,若Fragement定义有带参构造函数,则一定要定义public的默认的构造函数。即可解决此问题。


除了他说的public.还有一个就是弄个空的构造函数。


例如我是这样定义了我的fragment。带有了构造函数

public TestFragment(int index){

    mIndex = index;

}


然后我添加了一个这样的构造函数

public TestFragment(){

 

}



就解决了问题。

如果说的不对。或者有其他更好的建议 。请提出





0 0
原创粉丝点击