使用Builder 的诡异错误

来源:互联网 发布:js set 编辑:程序博客网 时间:2024/05/20 16:10

今天在activity 里声明了一个builder,结果悲剧了,因为在builder直接new了一个,因为此时activity还没有建立起来,而builder建立的时候,需要context, Builder a = new Builder(this);故而,错了。。。

总结:

builder不能在oncreate前new,因为用到了上下文。

错误类型为Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()