Fragment使用时遇到的二个问题

来源:互联网 发布:九世犹可以复仇乎 编辑:程序博客网 时间:2024/05/31 05:27
问题1:

Fragment(XXFragment) not attached to Activity 异常。

出现该异常,是因为Fragment的还没有Attach到Activity时,调用了如getResource()等,需要上下文Content的函数。解决方法,就是等将调用的代码写在OnStart()中。


问题2.

Fragment - InstantiationException: no empty Constructor


可能是你重写了构造方法,为了传一些实体变量进去,改成这样:

private Entity mEntity;  public YourFragment() {}  public static YourFragment getInstance(Entity mEntity) {    YourFragment fragment = new YourFragment();    fragment.mEntity = mEntity;    return fragment;  }






0 0
原创粉丝点击