开发者社区> 问答> 正文

使用RoboGuice @InjectFrament 时报错? 400 报错

使用RoboGuice @InjectFrament 时报错? 400 报错 我在Activity里面使用RoboGuice的@InjectFragment来初始化我自定义的Fragment,但运行出错了,代码如下:

public class CrimeActivity extends RoboFragmentActivity {
    private static final String TAG = CrimeActivity.class.getSimpleName();

    @Inject FragmentManager fm;
    // 这里想声明并初始化自定义的Fragment
    @InjectFragment(R.id.fragmentContainer) private CrimeFragment fragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_crime);
        RoboGuice.getInjector(this).injectMembers(this);
        Log.i(TAG, "CrimeActivity onCreate...");
    }
}

报错信息如下:

java.lang.NullPointerException: Can't inject null value into class com.android.criminalintent.CrimeActivity.fragment when field is not @Nullable

哪位高手对RoboGuice比较熟悉的,求助!!!

展开
收起
爱吃鱼的程序员 2020-06-03 13:53:52 435 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    没有用过

    找到了篇文章,不知道是否有用

    http://mobile.51cto.com/abased-426620.htm

    ######这个没有提到怎么用fragment的,不过还是谢谢!
    2020-06-03 16:42:21
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载