今天修改android代码的时候出现了一个java.lang.exceptionINinitializererror,在程序刚刚加载的时候会去调用单例模式(FDocument类):
FDocument.Instance().getKindList().clear(); FDocument.Instance().getGradeList().clear(); FDocument.Instance().getCustomerList().clear();来对数据进行初始化操作, 原本是好好的,但是由于我在FDocument类中我需要使用SharedPreferences,所以我让该类继承activity,但是一继承run一下,这下可好报出了
09-11 09:23:50.569: E/AndroidRuntime(22916): java.lang.ExceptionInInitializerError 09-11 09:23:50.569: E/AndroidRuntime(22916): at com.depart.followme.FrmWelCome$1.run(FrmWelCome.java:101) 09-11 09:23:50.569: E/AndroidRuntime(22916): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 的错误,这是为什么,我只是继承了一下activity啊?有大神可以指点小弟我么?
高洛峰2017-04-17 11:18:53
If your class is not an activity, you should not inherit the activity. The logic is very strange. Just because you use a sharedpreference, you should inherit the activity? ? ?
Yes, if an ordinary class wants to use context, just pass it in the constructor.